Help *First Programm* 😔 🤗🤓 Please leave a answer 🙂 | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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

21st Aug 2017, 6:17 PM
Ninj4
8 Antworten
+ 1
Make sure to define 'inp' and on line 5 change if to for.
21st Aug 2017, 7:29 PM
Alex
0
Okay, done
21st Aug 2017, 8:14 PM
Ninj4
0
But it doesn't work 😕
23rd Aug 2017, 7:15 AM
Ninj4
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 ?
23rd Aug 2017, 2:11 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
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
23rd Aug 2017, 6:14 PM
Ninj4
0
Remove the return statement then
23rd Aug 2017, 7:09 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
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
23rd Aug 2017, 7:30 PM
Ninj4
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
23rd Aug 2017, 8:05 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar