编程新手,不确定如何打印用户对列表问题的回答是否正确,然后将其添加到将在程序结束时显示的持续分数中
#number list test program
import random
import statistics
choosequestion = random.randint(1,4)
print('Welcome to the number list test')
print('e) Easy')
print('m) Medium')
print('h) Hard')
difficulty = input('Difficulty: ')
if difficulty == 'e':
print('Easy difficulty selected')
score = 0
questions = 2
quantity = 3
minimum = 1
maximum = 5
lists = random.sample(range(minimum, maximum), quantity)
if choosequestion == 1:
print ('What is the smallest number in this list?', lists)
finalmin = min = int(input(""))
elif choosequestion == 2:
print ('What is the biggest number in this list?', lists)
finalmax = max = int(input(""))
elif choosequestion == 3:
print ('What is the sum of numbers in this list?', lists)
finalsum = sum = int(input(""))
elif choosequestion == 4:
print ('What is the average of the numbers in this list?', lists)
average = statistics.mean = int(input(""))
##elif difficulty == 'm':
## print('Medium difficulty selected')
##
##elif difficulty == 'h':
## print ('Medium difficulty selected')
任何帮助都会很好,谢谢(运行程序时选择“e”开始,我已经注释掉了所有其他选项)
您可以参考下面的代码
python中的input()函数返回用户在控制台中键入的字符串。然后,您可以使用相等运算符==将输入字符串与正确答案进行比较。(当然,如果匹配,则为True)我已经完成了几行代码来演示:
将min()函数更改为max()、sum()或您自己的函数,以获得每个问题的正确答案
对于未来,许多事情可以帮助改进此代码:
相关问题 更多 >
编程相关推荐