Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Turn this code:

Python
lifelist = "Always", "look", "on", "the", "bright", "side", "of", "life!"]
print("\nPrac Test 1 life words:\n")
print(lifelist) 


Into this expected output:

Prac Test 1 life words:

0 is SYAWLA
1 is look
2 is NO
3 is the
4 is THGIRB
5 is side
6 is FO
7 is life!


Basically starting with 0, all odd numbers reverse the word in lifelist and changes into uppercase. As seen always turns into SYAWLA, etc. While all even numbers have the same are kept the same such as number 1 look.

What I have tried:

I have tried to do this using Python, as I am a beginner, I have had no luck so far.
Posted
Updated 6-May-22 9:21am
v2
Comments
CPallini 20-Apr-22 10:16am    
Post here your code, we could try to fix or improve it.
Mehdi Alizada 20-Apr-22 10:21am    
lifelist = "Always", "look", "on", "the", "bright", "side", "of", "life!"]
print("\nPrac Test 1 life words:\n")
print(lifelist)

Just a little step towards the solution...
Python
lifelist = ["Always", "look", "on", "the", "bright", "side", "of", "life!"]
print("\nPrac Test 1 life words:\n")
for i in range(0, len(lifelist)):
  print(i, lifelist[i])

Now you have to work a bit on even items.
 
Share this answer
 
Comments
Mehdi Alizada 21-Apr-22 1:53am    
I have tried to do cause the even ones to be upper case and to be in reverse.

so far I know that this is how you get it to be upper case but I dont know how to string it together with the original code to get an output for the expected result.

if i%2 == 0:
print(i, lifelist[i][::-1].upper())
else:
print(i, lifelist[i])

also to reverse it I know that you have to use the slicing method. however I dont know how to use it and dont know how to string that also together with the other 2 commands. I appreciate your help
 
Share this answer
 
lifelist = ["Always", "look", "on", "the", "bright", "side", "of", "life!"]

def reverse(s):
    str = ""
    for i in s:
      str = i + str
    return str


for i in range(0,len(lifelist)):
    if(i%2==0):
        lifelist[i]=reverse(lifelist[i]).upper()
    else:
        lifelist[i]=lifelist[i]
    print(i,'is', lifelist[i])
 
Share this answer
 
v2
Comments
Dave Kreskowiak 5-May-22 12:11pm    
DO NOT DO SOMEONES HOMEWORK FOR THEM. THEY ARE NOT LEARNING HOW TO THINK ABOUT THE PROBLEM WHEN YOU DO THIS!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900