Write a python program that takes a string as an input from the user and then modifies the string in such a way that the string always starts with an uppercase letter and the case of each subsequent letter is the opposite of the previous letter (uppercase character followed by a lowercase character followed by an uppercase character and so on). Finally, the modified string is printed to show the user.
I'm not allowed to use uppercase and lowercase function
What I tried so far :
user=input()
s=""
upper=True
if user[0]>='a' and user[0]<='z':
s+=chr(ord(user[0])-32)
else:
s+=user[0]
# s+=chr(ord(user[0])+32)
for i in range(1,len(user)):
if upper==True:
if user[i]>='A' and user[i]<='Z':
upper=False
s+=chr(ord(user[i])+32)
elif user[i]>='a'and user[i]<='z':
upper=False
s+=user[i]
# s+=chr(ord(user[i])-32)
else:
s+=chr(ord(user[i])-32)
# s+=user[i]
else:
if user[i]>='A' and user[i]<='Z':
upper=True
s+=user[i]
# s+=chr(ord(user[i])+32)
elif user[i]>='a' and user[i]<='z':
upper=True
# s+=user[i]
s+=chr(ord(user[i])-32)
else:
# s+=chr(ord(user[i])-32)
s+=user[i]
print(s)
after running its printing like
PyThOn PrOgRaMmInG�iS�vErY�eAsY
now don't know why there is question mark. It suppose to take space