+ 3
Help *First Programm* 😔 🤗🤓 Please leave a answer 🙂
I Made a programm, But there is an Error and I don't how to fix him. Programmpart: hallo = ["hey", "hello"] cmd = input() userin = cmd.lower() inp = userin.split (" ") def user(): for c in inp: for c in hallo: if c == "hey": print("Hey, Hey") if "whats" in inp and "up" in inp: print ("Nothing") And when I run the Programm and Type "Hey Whats up" in the input: Hey hey Nothing hey hey How I can do that the Output only came once? Ninja
8 Respuestas
+ 1
Make sure to define 'inp' and on line 5 change if to for.
0
Okay, done
0
But it doesn't work 😕
0
hallo = ["hey", "hello"]
cmd = input()
userin = cmd.lower()
inp = userin.split (" ")
def user():
for c in inp:
for c in hallo:
if c == "hey":
print("Hey, Hey")
return None
if "whats" in inp and "up" in inp:
print ("Nothing")
user()
Is this what you wanted ?
0
No when I type whats up it prints Nothing twice. I want it only once. With your Code he print no times, I don't Whats should I do
0
Remove the return statement then
0
Okay this ist my Programm and when you Run it and type "whats up whats the time" write it only came the answer from Whats up. Do you know how I can fix it?
https://code.sololearn.com/cOjKdaBhbb1q/?ref=app
0
It is because of the return statement in all if statements. Returning statement makes the program leave the function, so all your if are like if/elif. The first one to be correct will be the only one. If you remove those return statement, then it will be all good