Last active
May 9, 2020 18:54
-
-
Save BioSciEconomist/155aa26fb52e0b036a0feed7c88e82f8 to your computer and use it in GitHub Desktop.
Generate 4 digit addition problems for home school/quiz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------ | |
# PROGRAM NAME: addition problems.py | |
# DATE: 5/9/20 | |
# CREATED BY: MATT BOGARD | |
# PROJECT FILE: /Users/amandabogard/Google Drive/Python Scripts | |
#---------------------------------------------------------------- | |
# PURPOSE: generate basic addition problems | |
# --------------------------------------------------------------- | |
# references: modified from: https://codereview.stackexchange.com/questions/106464/generating-arithmetic-quiz-questions | |
# this program generates and grades random 4 digit addition problems | |
# if a student enters the wrong answer, it was modified from the original source to provide the correct answer | |
# before moving to the next question | |
name = input("What is your name? ") | |
print("Hello, "+name+". You will be completing a quiz that will ask you 5 questions adding numbers up to 4 digits. Try your best at each question and good luck!") | |
import random | |
from operator import add | |
count = 0 | |
score = 0 | |
while count <= 4: | |
op = add | |
x = random.randint(1000,9999) | |
y = random.randint(1000,9999) | |
if op == add: | |
print("What is", x, "+",y, "? ") | |
question_add = int(input()) | |
answer_add = op(x,y) | |
if question_add == answer_add: | |
print("Well done, this is correct!") | |
score = score + 1 | |
count = count + 1 | |
else: | |
print("Sorry, but this is incorrect.") | |
print("the correct answer is:") | |
print(x+y) | |
count = count + 1 | |
if count == 5: | |
print("Well done "+name+"! You have completed the quiz. You correctly answered "+str(score)+" questions.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment