Hayliann Pardo
Hayliann Pardo

Reputation: 11

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])

Upvotes: 0

Views: 1355

Answers (2)

ibadia
ibadia

Reputation: 919

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])

Upvotes: 0

Bialomazur
Bialomazur

Reputation: 1141

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])

Upvotes: 1

Related Questions