From f8ff18f3133f85bf8b3cd8d59037a4f8ecf9c765 Mon Sep 17 00:00:00 2001 From: Kenneth Odle Date: Tue, 8 Aug 2023 15:45:25 -0400 Subject: [PATCH] Added additional proportion files --- proportions-extra.py | 17 ++++++++ proportions-practice.py | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 proportions-extra.py create mode 100644 proportions-practice.py diff --git a/proportions-extra.py b/proportions-extra.py new file mode 100644 index 0000000..22301d5 --- /dev/null +++ b/proportions-extra.py @@ -0,0 +1,17 @@ +# print(1 + 2/3 + 3 + 4/5 - 7) + +x = 2/3 +print("10x = ", 10 * x ) +print("9x = ", 9*x) +print("10x - 9x = ", 10*x - 9*x) +print("x = ", x) + +print("-----------------------------") + +y = 4/9 +print(y) +print( 10 *y ) +print(9*y) + +print("-----------------------------") + diff --git a/proportions-practice.py b/proportions-practice.py new file mode 100644 index 0000000..a368821 --- /dev/null +++ b/proportions-practice.py @@ -0,0 +1,109 @@ +# converts string input (even fractions) to float +def string_frac(in_string): + if "/" in in_string: + nd = in_string.split("/") + n = float(nd[0]) + d = float(nd[1]) + ans = n/d + return ans + else: + ans = float(in_string) + return ans + + +# Simplest one-step addition +def one_step_add(): + import random + # Display problem + a = random.randint(-4,10) + b = random.randint(2,24) + print("x + ", a, " = ", b) + ans = float(input("x = ")) + answer = b-a + # Test input + if ans==answer: + print("Correct! \n") + else: + print("Try again") + print("The correct answer is ", answer, "\n") + + +# One-step additon with negative numbers +def one_step_subtract(): + import random + a = random.randint(-19,-1) + b = random.randint(2,24) + print(a, " + x = ", b) + ans = float(input("x = ")) + # test + answer = b-a + if ans==answer: + print("Correct! \n") + else: + print("Try again") + print("The correct answer is ", answer, "\n") + +# One-step multiply +def one_step_mult(): + # Uses string_frac() + import random + a = random.randint(1,11) + b = random.randint(2,24) + print(a, "x = ", b) + print("Round your answer to two decimal places.") + ans_in = (input("x = ")) + answer = round(b/a,2) + # test + if string_frac(ans_in)==answer: + print("Correct! \n") + else: + print("Try again") + print("The correct answer is ", answer, "\n") + + +# One-step divide +def one_step_div(): + import random + a = random.randint(1,11) + b = random.randint(2,24) + print("x/", a, " = ", b) + ans = float(input("x = ")) + answer = b*a + # test + if ans==answer: + print("Correct! \n") + else: + print("Try again") + print("The correct answer is ", answer, "\n") + + +# Two-step problems +def two_step(): + import random + # Uses string_frac() + a = random.randint(1,11) + b = random.randint(-7,12) + c = random.randint(2,36) + print(a, "x + ", b, " = ", c) + print("Round answer to two decimal places") + ans_in = input("x = ") + answer = (c-b)/a + # test + if round(string_frac(ans_in),2)==round(answer,2): + print("Correct! \n") + else: + print("Try again") + print("The correct answer is ", answer, "\n") + + +# test loop +for a in range(2): + one_step_add() + one_step_subtract() + one_step_mult() + one_step_div() + two_step() + print(" ") + +two_step() +two_step()