I need some help with some work I have tried everything I can think of and read the book over and over

Joined
Jul 25, 2024
Messages
23
Reaction score
1
I am having trouble doing the following problem print alternating case (PyThOn) here is my code
Code:
word = str(input("Please choose a word: "))
lengthOfWord = len(word)
every2ndLetter = word[1:lengthOfWord:2]
every1stLetter = word[0:lengthOfWord:2]
for char in range(lengthOfWord):
    w = every1stLetter[::1]
    o = every2ndLetter[::1]
    w = list(w)
    o = list(o)
    word = w.insert(1,o)
print(str(word))

this only one of my tries I am trying to do it using basic python only please help
 
Joined
Dec 10, 2022
Messages
115
Reaction score
26
Python:
word = 'python'
altered = []
for index, letter in enumerate(word):
    if index%2 == 0:
        altered.append(letter.upper())
    else:
        altered.append(letter)
        
print(''.join(altered))
 
Joined
Jul 25, 2024
Messages
23
Reaction score
1
Python:
word = 'python'
altered = []
for index, letter in enumerate(word):
    if index%2 == 0:
        altered.append(letter.upper())
    else:
        altered.append(letter)
       
print(''.join(altered))
thanks but i figured it out long since and with a shorter solution but thanks for taking the time to help
 
Joined
Jul 4, 2023
Messages
609
Reaction score
81
@menator01, what about if word = 'pyTHOn' ;)
Python:
word = input("Please choose a word: ").lower()
new_word = ''.join(
    w.upper() if i % 2 == 0 else w
    for i, w in enumerate(word)
)
print(new_word)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top