简体   繁体   中英

Write a program that takes in a input and reverse the users output?

The program repeats, ending when the user enters "Done", "done", or "d" for the line of text.

Ex: If the input is:

Hello there
Hey
done

then the output is:

ereht olleH
yeH

I have written most the program but I'm struggling with defining the user_string .

user_string = str(input())

while True:
    user_string = str(input())
    if user_string == 'Done' or mystring == 'done' or mystring == 'd':
        break
    print(user_string[::-1])

Not sure what mystring is supposed to do, as it just suddenly appears without any clear purpose.

However making judgement from the given code you should try:

# this line seems redundant, remove it. --> user_string = str(input())

while True:
    user_string = input() # str() not needed as input() returns a String by default.
    if user_string.lower() in {'done', 'd'}:
        break
    print(user_string[::-1])

In you if condition you have to compare user_string with Done, d or done instead of the variable mystring . Here is how it should be

#user_string = str(input()) you do not need this 

while True:
    user_string = str(input())
    if user_string == 'Done' or user_string == 'done' or user_string == 'd':
        break
    print(user_string[::-1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM