python将成绩写入文件_如何使用python将一个班级的数学测验成绩存储在记事本文件上?...

直到我的程序中有一个错误,我才把我的程序中的错误记录下来。我已经添加了下面的代码,所以请帮助我这一点,并建议我如何改进我的代码,以避免收到此错误消息。在import random

def questions():

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

print("Hello there",name,"! Please answer 10 random maths questions for this test!")

Class=input("Which class are you in?")

choice = random.choice("+-x")

finish = False

questionnumber = 0

correctquestions = 0

while finish == False:

choice = random.choice("+-x")

if questionnumber < 10 | questionnumber >= 0:

number1 = random.randrange(1,10)

number2 = random.randrange(1,10)

print((number1),(choice),(number2))

answer=int(input("What is the answer?"))

questionnumber = questionnumber + 1

if choice==("+"):

realanswer = number1+number2

if answer==realanswer:

print("That's the correct answer")

correctquestions = correctquestions + 1

else:

print("Wrong answer, the answer was",realanswer,"!")

if choice==("x"):

realanswer = number1*number2

if answer==realanswer:

print("That's the correct answer")

correctquestions = correctquestions + 1

else:

print("Wrong answer, the answer was",realanswer,"!")

elif choice==("-"):

realanswer = number1-number2

if answer==realanswer:

print("That's the correct answer")

correctquestions = correctquestions + 1

else:

print("Wrong answer, the answer was",realanswer,"!")

else:

finish = True

else:

print("Good job",name,"! You have finished the quiz")

print("You scored " + str(correctquestions) + "/10 questions.")

if ClassOfStudent==1:

Class=open('N:Class 1 Score.txt','a')

Class.write(name)

Class.write(str(correctquestions))

Class.close()

if ClassOfStudent==2:

Class=open('N:Class 2 Score.txt','a')

Class.write(name)

Class.write(str(correctquestions))

Class.close()

if ClassOfStudent==3:

Class=open('N:Class 3 Score.txt','a')

Class.write(name)

Class.write(str(correctquestions))

Class.close()

questions()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值