Python 我如何选择随机测试12次并以不同方式显示我的测试结果分数

Python 我如何选择随机测试12次并以不同方式显示我的测试结果分数,python,arrays,printing,Python,Arrays,Printing,经过数小时的研究,我很难制定这样的标准: #select random question 12 times #Display highest to lowest score in (alphabetical order) #Display highest to lowest score #Display highest to lowest average #However my quiz's coding is able to save the players name in a tex

经过数小时的研究,我很难制定这样的标准:

#select random question 12 times 
#Display highest to lowest score in (alphabetical order) 
#Display highest to lowest score 
#Display highest to lowest average

#However my quiz's coding is able to save the players name in a text file     (images will be provided) and score as well as the quiz works perfectly

#MY PYTHON QUIZ FILE AND RESULTS OF QUIZ IN TEXT FILE IN TERMS OF CLASS          IMAGE :http://gyazo.com/817bd04f8c28e66ee4c9e1f5142b01df

##THIS IS MY CODE : http://pastebin.com/bdHCcvxt

#Sorry i wasnt able to paste my code on as there was an error code
 on the site so please visit the link I provided. Thanks a lot.
要使用
input()
输入字符串,请改用
raw\u input()

以下是修改后的源代码:

name=raw_input ("what is your name?")
print ("Welcome", name, ", I am heisenberg and this is my quiz")       
begin = raw_input ("To begin enter 'heisenberg''")
if begin == ("heisenberg"):
    print ("Alright GOODLUCK!")
    score = 0

    class_no = ""
    while class_no not in ["1", "2", "3"]:
        class_no = raw_input("Please enter your class - 1, 2 or 3:")  # Asks the user for an input

print ("What is 5*10")
answer = raw_input ("Enter Answer: ")
if answer == "50":
    print ("Correct")
    score = score  + 1
else:
    print ("Incorrect")
    score =  score - 0

print ("What is 5*2")
answer = raw_input ("Enter Answer: ")
if answer == "10":
    print ("Correct")
    score = score  + 1
else:
    print ("Incorrect")
    score =  score - 0

print ("What is 5*3")
answer = raw_input ("Enter Answer: ")
if answer == "15":
    print ("Correct")
    score = score + 1
else:
    print ("Incorrect")
    score = score - 0

print ("What is 22+ 84")
answer = raw_input ("Enter Answer: ")
if answer == "106":
    print ("Correct")
    score = score + 1
else:
    print ("Incorrect")
    score = score - 0 

print ("What is 20/2")
answer = raw_input ("Enter Answer: ")
if answer == "10":
    print ("Correct")
    score = score + 1
else:
    print ("Incorrect")
    score = score  - 0

print ("What is 20/5")
answer = raw_input ("Enter Answer: ")
if answer == "4":
    print ("Correct")
    score = score + 1
else:
    print ("Incorrect")
    score = score - 0

print ("What is 1.1*4 ")
answer = raw_input ("Enter Answer: ")
if answer == "4.4":
    print ("Correct")
    score = score  + 1
else:
    print ("Incorrect")
    score = score - 1

print ("What is 7/7")
answer = raw_input ("Enter Answer: ")
if answer == "1":
    print ("Correct")
    score = score + 1
else:
    print ("Incorrect")
    score = score - 0

print ("What is 90-9")
answer = raw_input ("Enter Answer: ")


if answer == "81":
    print ("Correct")
    score = score + 1
else:
    print ("Incorrect")
    score = score - 0

print ("What is 41+51")
answer = raw_input ("Enter Answer: ")
if answer == "92":
    print ("Correct")
    score = score + 1
else:
    print ("Incorrect")
    score = score - 0

print ("What is 1 - 5")
answer = raw_input ("Enter Answer: ")
if answer == "-4":
    print ("Correct")
    score = score + 1
else:
    print ("Incorrect")
    score = score - 0

print ("What is 10/2")
answer = raw_input ("Enter Answer: ")
if answer == "5":
    print ("Correct")
    score = score + 1
else:
    print ("Incorrect")


print ("Thank you for playing my quiz", name,"you have scored,", score,"out of 12 points")

with open("class%s.txt" % class_no, "a") as my_class:
        my_class.write("{0}\n".format([name, score]))
以下是输出:

what is your name?suraj
('Welcome', 'suraj', ', I am heisenberg and this is my quiz')

To begin enter 'heisenberg''heisenberg
Alright GOODLUCK!

Please enter your class - 1, 2 or 3:1
What is 5*10

Enter Answer: 50
Correct
What is 5*2

Enter Answer: 10
Correct
What is 5*3

Enter Answer: 15
Correct
What is 22+ 84

Enter Answer: 106
Correct
What is 20/2

Enter Answer: 10
Correct
What is 20/5

Enter Answer: 4
Correct
What is 1.1*4 

Enter Answer: 4.4
Correct
What is 7/7

Enter Answer: 1
Correct
What is 90-9

Enter Answer: 81
Correct
What is 41+51

Enter Answer: 92
Correct
What is 1 - 5

Enter Answer: -4
Correct
What is 10/2

Enter Answer: 5
Correct
('Thank you for playing my quiz', 'suraj', 'you have scored,', 12, 'out of 12 points')

注意:您可能希望使用字典或列表存储问题和答案,然后循环浏览并比较相应的答案,而不是手动键入每个问题和答案。

您的具体问题是什么?“我在编码上有困难”对于这个网站来说太宽泛了。缩小范围-是什么让你这么难?克里皮说:看起来你在考普通中等教育证书@Brionius感谢您的关注,我的问题之一是我无法从我的编码中生成随机问题。@HughBothwell为什么;)?非常感谢您的帮助,您似乎已经在Python2.7中编辑了这段代码,我已经在Python3.3中检查了它,它不起作用,但它在2.7中起作用,我希望这段代码在3.3中,因为在3.3上编码比在2.7上编码更有效,如果我是正确的话?我主要关心的是,我想将这12个问题随机排列12次,以及当你完成测验时,我希望结果显示在(通过保存的记事本/文本文件结果,显示所有类)中,分数从高到低(按字母顺序排列)从高到低的分数从高到低的平均值这就是代码如何在课堂上保存我的结果:更不用说感谢您对我的代码困境的帮助和兴趣,谢谢您>洗牌12个问题,您将需要使用
随机
库和字典来存储问题和答案,>在文本文件中排序和显示:这很简单,一旦你做了随机部分,只需编写一个函数就可以了,检查一下,有一个
video.py
可以随机播放一组视频中的视频,这将对你有所帮助