Python 如何在int(输入)中生成一个单词作为答案; 导入时间 随机输入 lista='ACE','2','3','4','5','6','7','8','9','10','BOY','LADY','KING' 打印“你有”,random.choicelista i=intinput“你想买张新卡吗” 是=1 如果i==是: 打印“您的第二张卡是:”,random.choicelista

Python 如何在int(输入)中生成一个单词作为答案; 导入时间 随机输入 lista='ACE','2','3','4','5','6','7','8','9','10','BOY','LADY','KING' 打印“你有”,random.choicelista i=intinput“你想买张新卡吗” 是=1 如果i==是: 打印“您的第二张卡是:”,random.choicelista,python,if-statement,input,int,Python,If Statement,Input,Int,我想回答“是”,但不起作用。你能告诉我怎么做吗?试试这个: 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 = input('Do you want to get a new card: ') if i == "YES": print('Your se

我想回答“是”,但不起作用。你能告诉我怎么做吗?

试试这个:

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 = input('Do you want to get a new card: ')

if i == "YES":
    print('Your second card is:',random.choice(lista))
您使用的是字符串作为整数,无法将整数与字符串进行比较。

这将起作用

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 = input('Do you want to get a new card: ')

if i == "YES":
    print('Your second card is:',random.choice(lista))


请将i作为str输入,然后应用if操作。

您不需要调用str,因为input已经返回str。我已将其更改为@chepnert比较将永远不会发生,因为您无法首先将YES转换为int。什么不起作用?您是在提示下键入YES还是1?