+ 1

Problem with python validation loop.

Have a problem with a loop in python , i want this loop to let pass the user only if this user write one of the following variable : - chifoumi - starshooter_game - jeu_d_animation but for some reasons this doesnt work even when i type correctly , im pretty sure it's a logic problem , it's certainly not the way python validation loop work but i'm newbie so , i don't know a lot of ways to create this kind of thing. Here is the code : # sorry if the code isn't english... chifoumi = "chifoumi" starshooter_game = "Star shooter game" Jeu_d_animation = "Jeu d'animation" jeuchoisi = input(str("Le jeu auquel tu veux jouer : ")) while jeuchoisi != chifoumi or jeuchoisi != starshooter_game or jeuchoisi != Jeu_d_animation : print("tu t\'es trompé dans l\'orthographe ") jeuchoisi = input(str("Le jeu auquel tu veux jouer : ")) print("donc tu souhaites jouer à " + jeuchoisi )

21st Sep 2020, 8:44 PM
𝕢 ° | ℂ𝕒𝕋"𝕒𝕃𝕪:ℤ𝟛『☆゚.*・。 』
𝕢 ° | ℂ𝕒𝕋"𝕒𝕃𝕪:ℤ𝟛『☆゚.*・。 』 - avatar
3 Antworten
+ 6
Try creating a list with your valid choices, IE: choices = ["Chifoumi", "Starshooter, 'etc...'] Then create a loop which says:- If user input not in choice (create an action), else (create another action)
21st Sep 2020, 8:53 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
You mean one of strings to match..? Then your condition, you are using 'or' operator works as if one of all condition is True then expressions evaluated as true.. So using != is not correct.. Because atleast one of three will not equal and condition comes true ask you to reenter again in loop.. By the way, using while, if condition false, you don't get any output... Edit: If am not understood correctly what you are saying.. then pls add what is your expected output with a input...
21st Sep 2020, 8:52 PM
Jayakrishna 🇮🇳
+ 2
Ok thank you, i'll try it then.
22nd Sep 2020, 6:28 AM
𝕢 ° | ℂ𝕒𝕋"𝕒𝕃𝕪:ℤ𝟛『☆゚.*・。 』
𝕢 ° | ℂ𝕒𝕋"𝕒𝕃𝕪:ℤ𝟛『☆゚.*・。 』 - avatar