如何在 int(input); 中将单词作为答案;

import time

import random


lista=('ACE','2','3','4','5','6','7','8','9','10','BOY','LADY','KING')

print('You have got',random.choice(lista))

i=int(input('Do you want to get a new card'))

YES=1

if i == YES:

    print('Your second card is:',random.choice(lista))

我想将 aYES作为答案,但它不起作用。你能向我解释一下我该怎么做吗?


炎炎设计
浏览 159回答 2
2回答

倚天杖

尝试这个:import timeimport randomlista=('ACE','2','3','4','5','6','7','8','9','10','BOY','LADY','KING')print('You have got',random.choice(lista))i = input('Do you want to get a new card: ')if i == "YES":    print('Your second card is:',random.choice(lista))您使用“是”(字符串)作为整数,不能将整数与字符串进行比较。

小唯快跑啊

import timeimport randomlista=('ACE','2','3','4','5','6','7','8','9','10','BOY','LADY','KING')print('You have got',random.choice(lista))i=int(input('Do you want to get a new card'))YES=1if i == YES:    print('Your second card is:',random.choice(lista))我想将 aYES作为答案,但它不起作用。你能向我解释一下我该怎么做吗?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python