Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def three_variables_looper_arithmetic():
- a = input("enter a1: ")
- b = input("enter n: ")
- c = input("enter d: ")
- original = 0
- count_list = [[a], [b], [c]]
- loop = 0
- for count in count_list:
- if isinstance(count[0], str):
- original = float(eval(count[0]))
- count_list[loop][0] = original
- loop += 1
- return count_list[0][0], count_list[1][0], count_list[2][0]
- def three_variables_looper_geometric():
- a = input("enter a1: ")
- b = input("enter r: ")
- c = input("enter n: ")
- original = 0
- count_list = [[a], [b], [c]]
- loop = 0
- for count in count_list:
- if isinstance(count[0], str):
- original = float(eval(count[0]))
- count_list[loop][0] = original
- loop += 1
- return count_list[0][0], count_list[1][0], count_list[2][0]
- def input_checker(arithmetic_1_geometric_2, formula_num, L):
- if arithmetic_1_geometric_2 == 1:
- if formula_num == 1:
- three_variables_looper_arithmetic()
- elif formula_num == 2:
- three_variables_looper_arithmetic()
- elif formula_num == 3:
- a1 = input("enter a1: ")
- b = input("enter n: ")
- c = input("enter d: ")
- original = 0
- count_list = [[a1], [b], [c], [L]]
- loop = 0
- for count in count_list:
- if isinstance(count[0], str):
- original = float(eval(count[0]))
- count_list[loop][0] = original
- return count_list[0][0], count_list[1][0], count_list[2][0], count_list[3][0]
- elif arithmetic_1_geometric_2 == 2:
- if formula_num == 1:
- three_variables_looper_geometric()
- elif formula_num == 2:
- three_variables_looper_geometric()
- elif formula_num == 3:
- a1 = input("enter a1: ")
- b = input("enter n: ")
- original = 0
- count_list = [[a1], [b]]
- loop = 0
- for count in count_list:
- if isinstance(count[0], str):
- original = float(eval(count[0]))
- count_list[loop][0] = original
- return count_list[0][0], count_list[1][0]
- def stopper():
- stop_flag = False
- stop_or_continue = ""
- while stop_or_continue != "a" or "b":
- stop_or_continue = input("Stop?: ")
- if stop_or_continue == "a":
- stop_flag = True
- break
- if stop_or_continue == "b":
- stop_flag = False
- break
- if stop_flag:
- raise SystemExit
- print("Sequence & Series Solver")
- while True:
- choice = ""
- choices = ["a", "b", "c", "d"]
- while choice not in choices:
- choice = input("a for arithmetic\nb for geometric\n>> ")
- if choice == "a":
- arithmetic_1_geometric_2 = 1
- choice_2 = input("a for a_nth term\nb for sum\n>> ")
- if choice_2 == "a":
- print("a_nth=a1+(n-1)d")
- formula_num = 1
- a1, n, d = input_checker(arithmetic_1_geometric_2, formula_num, 0)
- result = a1+(n-1)*d
- print(result)
- elif choice_2 == "b":
- print("Sn=(n/2)(2a1+(n-1)d)\nSn=(n/2)(a1+L)\nEnter x if L is unknown")
- L = input("Enter L: ")
- if L == "x":
- formula_num = 2
- a1, n, d = input_checker(arithmetic_1_geometric_2, formula_num, L)
- result = (n/2)*(2*a1+(n-1)*d)
- print(result)
- else:
- formula_num = 3
- a1, n, d, L = input_checker(arithmetic_1_geometric_2, formula_num, L)
- result = (n/2)*(a1+L)
- print(result)
- elif choice == "b":
- arithmetic_1_geometric_2 = 2
- choice_2 = input("a for a_nth term\nb for sum\nc for sum_to_inf")
- if choice_2 == "a":
- print("a_nth=a1(r)^(n-1)")
- formula_num = 1
- a1, r, n = input_checker(arithmetic_1_geometric_2, formula_num, 0)
- result = a1*(r)**(n-1)
- print(result)
- elif choice_2 == "b":
- print("Sn=(a1(1-(r)^n))/(1-r)")
- formula_num = 2
- a1, r, n = input_checker(arithmetic_1_geometric_2, formula_num, 0)
- result = (a1(1-(r)**n))/(1-r)
- print(result)
- elif choice_2 == "c":
- print("S_inf=a1/(1/r)")
- formula_num = 3
- a1, r = input_checker(arithmetic_1_geometric_2, formula_num, 0)
- result = a1/(1-r)
- print(result)
- stopper()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement