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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值