我正在尝试使用python创建游戏,但在我的“class Character:”中,我想做类似的事情:
answer = raw_input('Which class do you want to play')
if answer = list_name[0]
self.stats = list_name
谢谢!
答案 0 :(得分:1)
首先请注意,您的if
声明应该有==
而不是=
此类情况也是使用python的in
语句的好时机,该语句将检查值是否与列表中的任何项匹配!你可以尝试这样的事情:
list_name = ['classA','classB','classC','classD']
answer = raw_input('Which class do you want to play: ')
#Check if the answer is one of the options in your list
if answer in list_name:
my_stats = answer
print 'great, your class is '+my_stats
else:
print 'sorry, ['+answer+'] is not an ok class'