[英]How do I properly input an else function?
else function on line 21 is failing否则第 21 行的 function 失败
enter image description here在此处输入图像描述
https://github.com/ksu-is/NameGen/blob/master/namegen.py 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:您正在检查用户是否输入字母字符 (.isalpha()),因此任何仅包含字母的单词都将通过 if 语句并打破循环,您不会像您一样检查输入是否只是“男孩”或“女孩”建议:你可以这样做:
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.如果需要,您可以省略 the.lower() 函数,这只会确保如果用户输入“Boy”或“boY”或任何其他大小写匹配。
hope this help希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.