European_countries = ['Germany' , 'France' , 'United Kingdom' , 'Italy' , 'Spain' , 'Switzerland' , 'Netherlands' , 'Greece' , 'Poland' , 'Ukraine' , 'Austria' , 'Belgium' , 'Sweden' , 'Croatia' , 'Norway' , 'Iceland' , 'Romania' , 'Denmark' , 'Malta' , 'Czech Rebublic' , 'Republic of Ireland' , 'Hungary' , 'Finland' , 'Bulgaria' , 'Cyprus' , 'Luxembourg' , 'Serbia' , 'Albania' , 'Slovenia' , 'Lithuania' , 'Montenegro' , 'Slovakia' , 'Estonia' , 'Latvia' , 'Macendonia' , 'Belarus' , 'Monaca' , 'Vatican City' , 'Moldova' , 'Bosnia and Herzegovia' , 'Gibraltar' , 'Andorra' , 'Liechtenstein' , 'Faroe Islands' , 'San Marino' , 'Isle of Man' , 'Aland Islands' , 'Guernsey' , 'Kingdom of the Netherlands' , 'Svalbard and Jan Mayen']
user = input('what is a European country. be exact ')
if user == European_countries [0:39]:
print('yes')
else:
print('nope')
当我从控制台中的列表中输入某项时,它总是转到else语句。它永远都不适用于印刷版。
谢谢您的帮助,我正在课堂上做一些小型项目,需要此帮助。
答案 0 :(得分:0)
您要测试的是用户是否在European_countries
中。在python中,您可以这样做
if user in European_countries:
print('yes')
else:
print('nope')