Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- USER_SCORE = 0
- questions = 0
- classnumber = ("1","2","3")
- name1= input("Enter Your Username: ")
- print("Hello, " + name1)
- print(" Welcome To Mazrui Arithmetic Quiz")
- classno = input("What class are you in?")
- while classno not in classnumber:
- print("Enter a valid class")
- print("ENTER ONLY THE NUMBER n 1 n 2 n3")
- classno=input("What class are you in?")
- while questions <10:
- for i in range(10):
- num1=random.randint(1,10)
- num2=random.randint(1,10)
- on=random.choice("*-+")
- multiply=num1*num2
- subtract=num1-num2
- addition=num1+num2
- if on == "-":#If "-" or subtract is randomly picked.
- print("MAKE SURE YOU ENTER A NUMBER OTHERWISE YOU WILL BE MARKED DOWN")
- questions+=1
- print(" Question" ,questions, "/10")
- uinput=input(str(num1)+" - "+str(num2))
- if uinput == str(subtract):
- USER_SCORE+=1
- print(" Correct, your USER_SCORE is: " ,USER_SCORE,)
- else:
- print (" Incorrect, the answer is: " +str(subtract))
- USER_SCORE+=0
- if on == "+":
- print("MAKE SURE YOU ENTER A NUMBER OTHERWISE YOU WILL BE MARKED DOWN")
- questions+=1
- print(" Question",questions, "/10")
- uinput=input(str(num1)+" + "+str(num2))
- if uinput == str(addition):
- USER_SCORE+=1
- print(" Correct, your USER_SCORE is: ",USER_SCORE,)
- else:
- print(" Incorrect, the answer is: " +str(addition))
- USER_SCORE+=0
- if on == "*":
- print("MAKE SURE YOU ENTER A NUMBER OTHERWISE YOU WILL BE MARKED DOWN")
- questions+=1
- print(" Question",questions, "/10")
- uinput=input(str(num1)+" * "+str(num2))
- if uinput == str(multiply):
- USER_SCORE+=1
- print(" Correct, your USER_SCORE is: " ,USER_SCORE,)
- else:
- print(" Incorrect, the answer is: " +str(multiply))
- USER_SCORE+=0
- if USER_SCORE >9:
- print("Well done," ,name1, "your score is" ,USER_SCORE, "/10")
- else:
- print(name1," your score is " ,USER_SCORE, "/10")
- def no1():
- with open("no1.txt", 'a')as file:
- file.write(str(name1)+" achieved a score of: "+str(USER_SCORE)+"/10 n")
- def no2():
- with open("no2.txt", 'a')as file:
- file.write(str(name1)+" achieved a score of "+str(USER_SCORE)+"/10 n")
- def no3():
- with open("no3.txt", 'a')as file:
- file.write(str(name1)+" achieved a score of "+str(USER_SCORE)+"/10 n")
- if classno=="1":
- no1()
- if classno=="2":
- no2()
- if classno=="3":
- no3()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement