Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jay Harper-Harrison
1,044 PointsSchool assignment
I have a school assignment but I don't really understand how to do it. I would really appreciate if somebody could help me.
Here's the question:
A primary school teacher wants a computer program to test the basic arithmetic skills of her students.
The program should generate a quiz consisting of a series of random questions, using in each case any two numbers and addition, subtraction and multiplication. The system should ask the student’s name, then ask 10 questions, output if the answer to each question is correct or not and produce a final score out of 10.
Analyse the requirements in detail and design, code, test and evaluate a program to meet these requirements.
3 Answers
Sean T. Unwin
28,690 PointsThis is my quick take on it with pseudo-code:
###
# Variables -- for you to decide scope of variables: global or not
###
# name
# number_of_question = 10
# current_question
# question_count = 0 # this will increase after each question
# operator_list = ['+', '*', '/'] # add, multiply, divide
# random_operator_for_current_question # generate random operator to use from operator_list
# random_a # generate on each new question
# random_b # generate on each new question
# question_result
# answer_result_dictionary -- current_question: question_result
# answer_total_correct
###
# Steps
###
# Ask name and store result in variable
# if current_question < number_of_questions
# Ask Question
# Show question number
# Generate random numbers for a and b
# Generate random operation
# Format question and display
# Calculate actual answer
# Compare answers
# Display result message
# Store result
# else if current_question == number_of_questions + 1
# End game
# Display game over message
# Display score
###
# Enhancements
###
# Range limit of a and b -- integers only, negative numbers, min, max
# Keep track of question operations -- how many questions were addition, etc
# Limit types of operations -- Allow x amount of division questions, etc
# Ask to play again
# Difficulty
# Types of numbers, increase max, allow negative numbers, allow floats
# Allow multiple operations in single question - may need additional numbers generated
That probably isn't exactly correct as far as logic and so forth, but I hope that will be enough to get you on the right track.
Best of luck and happy coding!
Kenneth Love
Treehouse Guest TeacherI'd probably have these basics steps:
- Ask and store a name
- Make 1 list with 10 members, each of which is a list (or tuple)
- Those inner lists/tuples have three members, two randomly selected numbers and a randomly selected
+/-/* - A score variable of 0
- Step through the outer list, making a string of the math question (
"{} {} {} = ".format(question[0], question[2], question[1])) and using that string as the question forinput() - Check to see if their provided input is the same as doing the math problem for real
- If so, increment the score
- Show the next question
- When all of the questions are used, show the score
Jay Harper-Harrison
1,044 PointsThank you!
Jay Harper-Harrison
1,044 PointsHow would I do this: "Make 1 list with 10 members, each of which is a list (or tuple) Those inner lists/tuples have three members, two randomly selected numbers and a randomly selected +/-/*"
Thank you so much for your help!
Kenneth Love
Treehouse Guest Teacherdef make_problems():
actions = ['+', '-', '*']
nums = range(1, 50)
problems = []
for _ in range(10):
problems.append([random.choice(nums), random.choice(nums), random.choice(actions)])
Tech Solutions
6,077 PointsSo the numbers and addition, multiplication etc need to be randomized on each question? I'd use Math.random to generate random numbers, you could also extend this to select which operator is used. For example if you stored them in an array [+, -, *, /] and used Math.random to randomly pick one of them each time a question generated. Hopefully this helps a bit, if you can get this working then the rest should be easy, store the score out of 10 in a variable etc.
Kenneth Love
Treehouse Guest TeacherThanks for the info! I think Jay Harper-Harrison is looking specifically for Python solutions, though.
Jay Harper-Harrison
1,044 PointsJay Harper-Harrison
1,044 Pointsthanks