Take a string that contains at least four characters from user input. Replace all the characters that are in odd positions (NOT index values) with hashes, '#'. Print the resulting string.
Requirement: Must use the for loop and the if/else statement.
input is: abcdef
s = input()
t = ''
for i in range(len(s)):
if (i%2)!=0:
t = t + s[i]
else:
print('#')
print(t)
result should be:
#b#d#f
Aucun commentaire:
Enregistrer un commentaire