Advertisement
MahdeenSky

Sequence/Solver

Feb 26th, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.64 KB | None | 0 0
  1. def three_variables_looper_arithmetic():
  2.     a = input("enter a1: ")
  3.     b = input("enter n: ")
  4.     c = input("enter d: ")
  5.     original = 0
  6.     count_list = [[a], [b], [c]]
  7.     loop = 0
  8.     for count in count_list:
  9.         if isinstance(count[0], str):
  10.             original = float(eval(count[0]))
  11.             count_list[loop][0] = original
  12.         loop += 1
  13.     return count_list[0][0], count_list[1][0], count_list[2][0]
  14.  
  15.  
  16. def three_variables_looper_geometric():
  17.     a = input("enter a1: ")
  18.     b = input("enter r: ")
  19.     c = input("enter n: ")
  20.     original = 0
  21.     count_list = [[a], [b], [c]]
  22.     loop = 0
  23.     for count in count_list:
  24.         if isinstance(count[0], str):
  25.             original = float(eval(count[0]))
  26.             count_list[loop][0] = original
  27.         loop += 1
  28.     return count_list[0][0], count_list[1][0], count_list[2][0]
  29.  
  30.  
  31.  
  32. def input_checker(arithmetic_1_geometric_2, formula_num, L):
  33.     if arithmetic_1_geometric_2 == 1:
  34.         if formula_num == 1:
  35.             three_variables_looper_arithmetic()
  36.  
  37.         elif formula_num == 2:
  38.             three_variables_looper_arithmetic()
  39.  
  40.         elif formula_num == 3:
  41.             a1 = input("enter a1: ")
  42.             b = input("enter n: ")
  43.             c = input("enter d: ")
  44.             original = 0
  45.             count_list = [[a1], [b], [c], [L]]
  46.             loop = 0
  47.             for count in count_list:
  48.                 if isinstance(count[0], str):
  49.                     original = float(eval(count[0]))
  50.                     count_list[loop][0] = original
  51.             return count_list[0][0], count_list[1][0], count_list[2][0], count_list[3][0]
  52.            
  53.     elif arithmetic_1_geometric_2 == 2:
  54.         if formula_num == 1:
  55.             three_variables_looper_geometric()
  56.        
  57.         elif formula_num == 2:
  58.             three_variables_looper_geometric()
  59.  
  60.         elif formula_num == 3:
  61.             a1 = input("enter a1: ")
  62.             b = input("enter n: ")
  63.             original = 0
  64.             count_list = [[a1], [b]]
  65.             loop = 0
  66.             for count in count_list:
  67.                 if isinstance(count[0], str):
  68.                     original = float(eval(count[0]))
  69.                     count_list[loop][0] = original
  70.             return count_list[0][0], count_list[1][0]
  71.  
  72.  
  73. def stopper():
  74.     stop_flag = False
  75.     stop_or_continue = ""
  76.     while stop_or_continue != "a" or "b":
  77.         stop_or_continue = input("Stop?: ")
  78.         if stop_or_continue == "a":
  79.             stop_flag = True
  80.             break
  81.         if stop_or_continue == "b":
  82.             stop_flag = False
  83.             break
  84.     if stop_flag:
  85.         raise SystemExit
  86.  
  87.  
  88. print("Sequence & Series Solver")
  89.  
  90. while True:
  91.     choice = ""
  92.     choices = ["a", "b", "c", "d"]
  93.     while choice not in choices:
  94.         choice = input("a for arithmetic\nb for geometric\n>> ")
  95.  
  96.     if choice == "a":
  97.         arithmetic_1_geometric_2 = 1
  98.         choice_2 = input("a for a_nth term\nb for sum\n>> ")
  99.  
  100.         if choice_2 == "a":
  101.             print("a_nth=a1+(n-1)d")
  102.             formula_num = 1
  103.             a1, n, d = input_checker(arithmetic_1_geometric_2, formula_num, 0)
  104.             result = a1+(n-1)*d
  105.             print(result)
  106.  
  107.         elif choice_2 == "b":
  108.             print("Sn=(n/2)(2a1+(n-1)d)\nSn=(n/2)(a1+L)\nEnter x if L is unknown")
  109.             L = input("Enter L: ")
  110.             if L == "x":
  111.                 formula_num = 2
  112.                 a1, n, d = input_checker(arithmetic_1_geometric_2, formula_num, L)
  113.                 result = (n/2)*(2*a1+(n-1)*d)
  114.                 print(result)
  115.             else:
  116.                 formula_num = 3
  117.                 a1, n, d, L = input_checker(arithmetic_1_geometric_2, formula_num, L)
  118.                 result = (n/2)*(a1+L)
  119.                 print(result)
  120.    
  121.     elif choice == "b":
  122.         arithmetic_1_geometric_2 = 2
  123.         choice_2 = input("a for a_nth term\nb for sum\nc for sum_to_inf")
  124.  
  125.         if choice_2 == "a":
  126.             print("a_nth=a1(r)^(n-1)")
  127.             formula_num = 1
  128.             a1, r, n = input_checker(arithmetic_1_geometric_2, formula_num, 0)
  129.             result = a1*(r)**(n-1)
  130.             print(result)
  131.  
  132.         elif choice_2 == "b":
  133.             print("Sn=(a1(1-(r)^n))/(1-r)")
  134.             formula_num = 2
  135.             a1, r, n = input_checker(arithmetic_1_geometric_2, formula_num, 0)
  136.             result = (a1(1-(r)**n))/(1-r)
  137.             print(result)
  138.  
  139.         elif choice_2 == "c":
  140.             print("S_inf=a1/(1/r)")
  141.             formula_num = 3
  142.             a1, r = input_checker(arithmetic_1_geometric_2, formula_num, 0)
  143.             result = a1/(1-r)
  144.             print(result)
  145.    
  146.     stopper()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement