使用id/else语句和随机变量/字典/列表进行测验

2024-09-27 07:18:10 发布

您现在位置:Python中文网/ 问答频道 /正文

Quiz making instructions

我开始编写代码

from random import randint, shuffle

numbers = {1:'\u4e00', 2:'\u4e8c', 3:'\u4e09', 4:'\u56db', 5:'\u4e94', \
    6:'\u516d', 7:'\u4e03', 8:'\u516b', 9:'\u4e5d', 10:'\u5341'}

x=randint(1,10)



print('Welcome to our quiz on Chinese/Japanese numerals.')

input('What is the Value of ' +numbers[x]  +'?' )


if 1 == '\u4e00' : 
    print('Congratulations! Let us continue then, consider:')
else:
    print( 'Congratulations! Let us continue then, consider:')
    input (['\u4e00', '\u4e8c', '\u4e09', '\u56db','\u4e94', \
    '\u516d', '\u4e03', '\u516b', '\u4e5d', '\u5341'])
    input ('At which position is the value of ' +numbers[x] +'?' )

代码的if和else部分有问题。我已经能够通过问第一个问题和插入随机的汉字来设置测验的开始,但是我有一个问题,接下来是“错误答案,等于”语句的一部分。如何确定用户在提示符中插入的内容是正确的还是不正确的?你知道吗


Tags: 代码inputprintrandintnumbersu4e00u56dbu4e8c
1条回答
网友
1楼 · 发布于 2024-09-27 07:18:10

How do i establish that what the user inserts into the prompt is correct or incorrect

捕获变量中的输入值,并执行等价性测试:

val = input('What is the Value of ' +numbers[x]  +'?' )

if val == x:
    # input is correct

else:
    # input is not correct

相关问题 更多 >

    热门问题