简体   繁体   English

如何正确输入 else function?

[英]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.

相关问题 我该如何解决? (其他功能) - how do i fix this? (else function) 如何正确使用 args 或 kwargs 来将它们用作 function 中的回归量输入变量? - How do I use args or kwargs for dicts properly to use them as Regressor input variables in function? 如何使输入与其他内容打印在同一打印件中? - How do I make an input to be printed in the same print as something else? 如何正确将参数传递给函数 - How do I properly pass an argument to a function 如何将python函数定义(以及其他任何内容)与RegEx相匹配? - How do I match a python function definition (and nothing else) with RegEx? 如何在字典中使用带有时间戳的 if-else function? - How do I use the if-else function with timestamp in dictionary? 如何正确格式化Spark数据帧以输入到LDA拟合中? - How do I properly format a Spark dataframe for input to LDA fitting? 每次用户输入后如何正确显示菜单? - How do I display the menu properly after each user input? 如何接受函数作为输入? - How do I accept a function as an input? 我如何正确使用函数调用。 我要做2批python脚本。 一个在输入中,另一个在输出中 - How do i use function call properly. I am gonna do 2 batch python script. The one is in input the other one is output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM