Hi there so I have this code. It works well (has also taught me alot about Python as I am new and a bit of a beginner but catching up very well.) Anyway I want to shuffle the questions in the following code. I understand the idea of random.shuffle and arrays. Just not sure howto put it together and what fits best
def game(): #defines the games script
start_time = time.time() #starts game timer.
correct = 0 #recalls amount of correct questions.
wrong = 0
time.sleep(2) #sleep function pauses game for 2 seconds.
list1 = ["10","7","13","4","1","6","9","12","17","2"] #list of answers, if statements check answer for each question. i.e: 1 number = answer for 1 question.
print "\nQuestion 1:\n" #printed text.
print "First question: _ - 8 = 2" #prints user question.
print "a, 10" #prints question hint.
print "b, 9" #prints question hint.
print "c, 13" #prints question hint.
list1 = raw_input("Your answer: ") #asks user to input answer.
if list1 == "10": #checks list above for answer.
correct += 1 #adds 1 to correct total.
print "\n\t Wonderful, correct",list1,"- 8 = 2\n" #printed text.
else: #if not correct, else checks and chooses wrong.
wrong +=1 #adds 1 to wrong total.
print "\n\tSorry you got that number wrong. The correct number was 10\n" #printed text.
Aucun commentaire:
Enregistrer un commentaire