-3

I want to write a program that prompts the root user to enter the word and then capitalizes (converts to a capital letter) every other letter from the word. So if a user enters the word rhinoceros, the program will print rHiNoCeRoS.

devd
  • 370
  • 10
  • 28
Draga
  • 1
  • 1

1 Answers1

0

Well, strings are immutable, so you will have to build a new string. One way would str.join the elements produced by a conditional generator that uppercases characters based on their index:

# inp = input()
inp = 'rhinoceros'
outp = ''.join(c.upper() if i%2 else c for i, c in enumerate(inp))
print(outp)
# 'rHiNoCeRoS'
user2390182
  • 72,016
  • 6
  • 67
  • 89