简体   繁体   中英

How do I properly input an else function?

else function on line 21 is failing

enter image description here

https://github.com/ksu-is/NameGen/blob/master/namegen.py

need some tips to make this run properly thank you!

You are checking if the user enters alphabets characters (.isalpha()), so any word that contains only letters will pass the if statement and break the loop, your not checking whether the input is only 'boy' or 'girl' as you suggests: you can do:

if baby_gender.lower() in ["boy", "girl"]:

You can omit the.lower() functions if you want, this would simply ensure that if the user enters "Boy" or "boY" or any other case will match.

hope this help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM