+ 2
how to make the 3rd line write depending on what the person writes?
and how to make print write any of the written answers by itself deciding what to choose? randomly like this #or print("- :)") #or print("- I see")???? I would like that when a person writes, for example, "Good" the phrase "I glad" is issued, if a person writes "Bad" then "Oh, tell me more about that, why so?" how to do it and how to make the code itself choose the answer to which the person will give from the proposed options? https://code.sololearn.com/cjw3qtj0677l/?ref=app
11 odpowiedzi
+ 5
Yua Chan the if statement conditionals need fixing up.
if x == "Bad" or "Not good" or "Difficult" or "Do you care?":
The code attempts to compare the input string x with several strings, but it only compares x with the first one. Here is a correction:
if x == "Bad" or x=="Not good" or x=="Difficult" or x=="Do you care?":
And a better way is to use the 'in' operator on a tuple of strings:
if x in ("Bad", "Not good", "Difficult", "Do you care?"):
+ 4
For each elif you need to do the "x in (...)".
+ 4
Yua Chan often it helps to read the error message to find out the problem. The two-line snippet has an indentation error. The print statement should be indented.
elif x in ("yes?"):
print(..)
Consider that when there is only one item to compare, then a simple comparison is more conventional.
if x=="yes?":
+ 3
After correcting the conditionals, I think you would want to adjust the indentations so that the if statements are at the same level and not nested. That will allow the remaining word comparisons to occur if the first set of words do not match.
Furthermore, after adjusting indentation levels, I have another improvement to suggest. Because only one of the if statements would be true, I recommend using elif instead of if on the last three if statements.
+ 2
Brian OOOOOOMG ITS WORKED OOOMGGG THANK YOU SO MATCH
+ 1
Brian elif? ahhhh that is it
+ 1
Ausgrindtube
elif x in("yes?")
print(..)
it doesn't work, it throws an error
+ 1
Yooo
0
Brian
print("-hi cutie, how are you?")
x = input()
print("- " + x)
if x in ("Bad", "Not good", "Difficult"):
print("- Oh, tell me more about that, why so?")
elif x == "Good" or "Great" or "Nice" or "Perfect" or "Marvelously" or "Amazing" or "Wonderful":
print("- I glad")
elif x == "What?" or "Who are you?" or "What the hell?" or "What the hell, who are you?":
print("- Oh, i'm sorry, I didn't introduce myself")
elif x == "Good, and you?":
print("- Oh, amazing, thanks")
doesn't work as it should((((((((
0
You also have a random = input() at the end of the elif statements, it was causing an error until I ran it with those removed
0
Madilyn Smith I know, I just wanted to add one more thing