davegimo

es2 giovanni

May 4th, 2022 (edited)
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. def mix_stringhe(s1,s2):
  2.  
  3.     if len(s2) > len(s1):
  4.         s1 = s1 + "*" * (len(s2)-len(s1))
  5.  
  6.     if len(s1) > len(s2):
  7.         s2 = s2 + "*" * (len(s1)-len(s2))
  8.  
  9.  
  10.     s3 = ""
  11.  
  12.     for i in range(len(s1)):
  13.         s3 = s3 + s1[i] + s2[i]
  14.  
  15.     return s3
  16.  
  17.  
  18. def mix_stringhe2(s1,s2):
  19.  
  20.     s3 = ""
  21.  
  22.     if len(s1) >= len(s2):
  23.         lunghezza = len(s1)
  24.     else:
  25.         lunghezza = len(s2)
  26.  
  27.     for i in range(lunghezza):
  28.         if i < len(s1):
  29.             s3 += s1[i]
  30.         else:
  31.             s3 += "*"
  32.  
  33.  
  34.         if i < len(s2):
  35.             s3 += s2[i]
  36.         else:
  37.             s3 += "*"
  38.  
  39.     return s3
  40.  
  41.  
  42. s1 = "ciao"
  43. s2 = "federico"
  44.  
  45. risultato = mix_stringhe2(s1,s2)
  46. print(risultato)
  47.  
  48.    
  49.    
  50.  
Add Comment
Please, Sign In to add comment