用casefold-python检查if语句字符串
这是一个简单的程序来检查你的年龄,但我不明白为什么它不起作用。我知道这和.casefold()有关,因为当我取出它时,它是有效的,但我不想为每个月的每个单一资本化可能性添加一个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(
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']中出生,请尝试