Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用casefold-python检查if语句字符串_Python - Fatal编程技术网

用casefold-python检查if语句字符串

用casefold-python检查if语句字符串,python,Python,这是一个简单的程序来检查你的年龄,但我不明白为什么它不起作用。我知道这和.casefold()有关,因为当我取出它时,它是有效的,但我不想为每个月的每个单一资本化可能性添加一个if语句。我做错了什么 user_birth_year = input('What year were you born? ') print('\n') user_birth_month = input('What month were you born? ') if user_birth_month.casefold(

这是一个简单的程序来检查你的年龄,但我不明白为什么它不起作用。我知道这和.casefold()有关,因为当我取出它时,它是有效的,但我不想为每个月的每个单一资本化可能性添加一个if语句。我做错了什么

user_birth_year = input('What year were you born? ')
print('\n')
user_birth_month = input('What month were you born? ')

if user_birth_month.casefold() == ['April', 'January']:
    print(2020 - int(user_birth_year))

实现这一点的标准方法是对两个字符串进行大小写折叠

如果用户输入.casefold()=“April”.casefold():
#做一件事
如果要选择多个,请折叠整个列表


#做一件事

您应该使用
大写()

user\u birth\u year=input('您出生的年份?'))
打印(“\n”)
user_birth_month=输入('您出生的月份?')
如果用户在['April'、'Janur']中出生月份大写():
打印(2020年-整数(用户出生年份))

您的
if
语句有问题。它应该是
中的
,而不是
=
。还有一件事,在比较字符串时,它们通常将所有字符串的大小写都降低,而不是大写

if user_birth_month.lower() in ['april', 'january']:

如果用户在['april'、'Janur']中出生,请尝试