python第二周小测验答案_做一个小测验2个正确答案

对于二月,我试着去做,这样它就有3个正确的答案,关于28,29,28月的天数,但当我试图改变时,它似乎不起作用user = int(input(""))

if month == "January":

answer = 31

elif month == "Feburary":

answer = 28

^{pr2}$

我意识到在输入中使用整数有一个问题,但是我不确定如何用逗号来解决这个问题,而且它也不允许我在28和29之间加一个空格。在

以下是代码的其余部分:import random

import shelve

from tkinter import *

result = []

highscore = []

root = Tk()

highscore = 0

correct = 0

d = shelve.open('highscore.txt')

d['highscore'] = highscore

d.close()

name = input("What is your name: ")

print ("Hello there",name,"!")

for count in range(12):

month = random.choice(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"])

while month in result:

month = random.choice(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"])

result.append(month)

print ("How many Days in?", month)

user = int(input(""))

if month == "January":

answer = 31

elif month == "February":

answer = 28,29 or 29 or 28

elif month == "March":

answer = 31

elif month == "April":

answer = 30

elif month == "May":

answer = 31

elif month == "June":

answer = 30

elif month == "July":

answer = 31

elif month == "August":

answer = 31

elif month == "September":

answer = 30

elif month == "October":

answer = 31

elif month == "November":

answer = 30

elif month == "December":

answer = 31

if user == answer:

print("Correct!")

correct = correct + 1

else:

print ("Wrong, the correct answer was", answer)

if correct > highscore:

highscore = correct

print (name,", You Beat The Highscore and got",highscore,"Out Of 12")

photo = PhotoImage(file='/Users/HoneyCentaur/Desktop/Approval.gif')

photo_label = Label(image=photo)

photo_label.grid()

photo_label.image = photo

text = Label(text=" ")

text.grid()

root.deiconify()

root.mainloop()

else:

print (name, ", You Got", correct, "Out Of 12")

d = shelve.open('highscore.txt')

d['highscore'] = highscore

d.close()

你可能感兴趣的:(python第二周小测验答案)