import random def division(): global num1 global num2 while num1 % num2 != 0: num1 = random.randint(1,144) num2 = random.randint(1,144) print("Weclome to the Lower School Arithmetic Quiz. Please enter your name below.") name = input().title() class_name = input("Which class do you wish to input results for? ") print (name, ", Welcome to the arithmetic test!") score = 0 question = 0 global num1 global num2 while question < 10: operator = random.randint(1,4) num1 = random.randint(1,12) num2 = random.randint(1,12) question += 1 if operator == 1: print("What is", num1, "+", num2,"?") while True: try: user_ans = int(input("")) break except ValueError: print ("That is not a valid answer") ans = num1 + num2 elif operator == 2: print("What is", num1, "*", num2,"?") while True: try: user_ans = int(input("")) break except ValueError:1 print ("That is not a valid answer") ans = num1 * num2 elif operator == 3: division() if num2 > num1: print("What is", num2, "/", num1,"?") while True: try: user_ans = int(input("")) break except ValueError: print ("That is not a valid answer") ans = num2 // num1 elif num1 > num2: #division() print("What is", num1, "/", num2,"?") while True: try: user_ans = int(input("")) break except ValueError: print ("That is not a valid answer") ans = num1 // num2 else: print("What is", num1, "-", num2,"?") while True: try: user_ans = int(input("")) break except ValueError: print ("That is not a valid answer") ans = num1 - num2 if user_ans == ans: print("Correct") score += 1 else: print("Incorrect") print("Well done", name, "you scored", score, "/10") class_name = class_name + ".txt" file = open(class_name , 'a') name = (name) file.write(str(name + " : " )) file.write(str(score)) file.write('\n') file.close() viewscore = input("Do you wish to view previous results for your class?").lower() if viewscore == "yes".lower(): f = open(class_name, 'r') file_contents = f.read() print (file_contents) f.close() elif viewscore != "yes".lower(): print ("Press any key to exit") ex = input ("")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question