0

how do I make the program ask for a name and then alternate the result in uppercase and lowercase?

Example:

How is your name? george

Hello GeOrGe

Thanks

Max dab
  • 9
  • 3
  • 3
    Does this answer your question? [Python Alternate Cases](https://stackoverflow.com/questions/45973151/python-alternate-cases) – Tunc Demircan Apr 30 '21 at 08:34

2 Answers2

1
print("How is your name?");
name = input();
list(name)
letters = list(name)
final_word = ""
for x in range(len(name)):
    if x % 2 == 0:
        final_word += letters[x].upper()
    else:
        final_word += letters[x].lower()
else:
    print("Hello" + final_word)

I think this code should work

Filip
  • 11
  • 2
1

you can use list comprehension -

s =  input()
s  = ''.join(item.upper() if index%2 ==0  else item.lower() for index,item in enumerate(s))
Nk03
  • 14,699
  • 2
  • 8
  • 22