Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | None | 0 0
  1. def linear(a, b, c):
  2.  
  3.     if a == 0:
  4.  
  5.         if b == c:
  6.             print("x - любое число")
  7.         else:
  8.             print("делить на ноль нельзя! решений нет")
  9.     else:
  10.  
  11.         print((c-b)/a)
  12.  
  13.  
  14. def squarer(a,b,c):
  15.  
  16.     if a == 0:
  17.         linear(a,b,c)
  18.         return
  19.  
  20.     D = b**2 - 4*a*c
  21.  
  22.     if D > 0:
  23.         print("x1 =", (-b+D**(0.5))/(2*a))
  24.         print("x2 =", (-b - D ** (0.5)) / (2 * a))
  25.     elif D == 0:
  26.         print(-b/(2*a))
  27.     else:
  28.         print("корней нет")
  29.  
  30.  
  31. def four_ex(a,b,c):
  32.     if a == 0:
  33.         squarer(b,0,c)
  34.         return
  35.  
  36.     D = b**2 - 4*a*c
  37.  
  38.     if D > 0:
  39.         x1 = (-b+D**(0.5))/(2*a)
  40.         x2 = (-b - D ** (0.5)) / (2 * a)
  41.         if x1 >= 0:
  42.             print("x1 =", x1**0.5)
  43.         else:
  44.             print("x1 не существует")
  45.         if x2 >= 0:
  46.             print("x2=", x2**0.5)
  47.         else:
  48.             print("x2 не существует")
  49.     elif D == 0:
  50.         x = -b/(2*a)
  51.         if x >= 0:
  52.             print(x)
  53.         else:
  54.             print("x не существует")
  55.     else:
  56.         print("корней нет")
  57.  
  58.  
  59. print("Какой вид уравнений хотите решить? 1)ax+b=c ; 2)ax^2+bx+c=0; 3)ax^4+bx^2+c=0")
  60. choice = input("Номер вида уравнения:")
  61.  
  62. if choice == "1":
  63.     print("Решаем уравнение вида ax+b=c. Введите коефициенты:")
  64.     a = int(input("a="))
  65.     b = int(input("b="))
  66.     c = int(input("c="))
  67.     linear(a,b,c)
  68.  
  69. elif choice == "2":
  70.     print("Решаем уравнение вида ax^2+bx+c = 0. Введите коефициенты:")
  71.     a = int(input("a="))
  72.     b = int(input("b="))
  73.     c = int(input("c="))
  74.     squarer(a,b,c)
  75. elif choice == "3":
  76.     print("Решаем уравнение вида ax^4+bx^2+c = 0. Введите коефициенты:")
  77.     a = int(input("a="))
  78.     b = int(input("b="))
  79.     c = int(input("c="))
  80.  
  81.     four_ex(a,b,c)
  82.  
  83. else:
  84.     print("Такого типа нет")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement