fork download
  1. def read_op():
  2. iput = input("Выберите операцию: 1 - простые операции, 2 - расширенные опереции, 3 - тригонометрические действия с градусами, 4 - перевод в другую систему исчисления")
  3. while not('1' <= iput <= '4'):
  4. print('Неверный ввод')
  5. iput = input("Выберите операцию: 1 - простые операции, 2 - расширенные опереции, 3 - sin, cos для градусов, 4 - перевод в другую систему исчисления")
  6. return int(iput)
  7.  
  8.  
  9. def extended_op():
  10. import math
  11. print("Выберите операцию: 1 - возведение в степень, 2 - остаток от деления, 3 - нахождение корня")
  12. vib = input()
  13. while not('1' <= vib <= '3'):
  14. print('Неверный ввод')
  15. vib = input("Выберите операцию: 1 - возведение в степень, 2 - остаток от деления, 3 - нахождение корня")
  16. vib = int(vib)
  17. if vib == 1:
  18. print ("Введите число")
  19. value = input()
  20. while not(value.isdigit()):
  21. print('Неверный ввод')
  22. value = input("Введите число")
  23. value = int(value)
  24. print ("введите степень")
  25. stepen = input()
  26. while not(stepen.isdigit()):
  27. print('Неверный ввод')
  28. stepen = input("Введите число")
  29. stepen = int(stepen)
  30. print (value ** stepen)
  31. elif vib == 2:
  32. print("Введите число 1")
  33. value1 = input()
  34. while not (value1.isdigit()):
  35. print('Неверный ввод')
  36. value1 = input("Введите число 1")
  37. value1 = int(value1)
  38. print("Введите число 2")
  39. value2 = input()
  40. while not (value2.isdigit()):
  41. print('Неверный ввод')
  42. value2 = input("Введите число 2")
  43. value2 = int(value2)
  44. if value2 == 0:
  45. print ("На ноль делить нельзя")
  46. else:
  47. print (value1 % value2)
  48. else:
  49. print("Введите число")
  50. value = input()
  51. while not (value.isdigit()):
  52. print('Неверный ввод')
  53. value = input("Введите число")
  54. value = int(value)
  55. print (math.sqrt(value))
  56.  
  57.  
  58. def calc_degrees():
  59. import math
  60. print("Введите: 1 - sin(), 2 - cos()")
  61. vib = input()
  62. while not('1' <= vib <= '2'):
  63. print('Неверный ввод')
  64. print("Введите: 1 - sin(), 2 - cos()")
  65. vib = input()
  66. vib = int(vib)
  67. print("Введите угол в градусах")
  68. angle = input()
  69. while not(angle.isdigit()):
  70. print('Неверный ввод')
  71. angle = input("Введите угол в градусах")
  72. angle = int(angle)
  73. if vib == 1:
  74. print(math.sin(angle / 360 * math.pi * 2))
  75. else:
  76. print(math.cos(angle / 360 * math.pi * 2))
  77.  
  78.  
  79. def calc_simple():
  80. print('Введите первое число:')
  81. a = input()
  82. while not (a.isdigit()):
  83. print('Неверный ввод')
  84. a = input("Введите число")
  85. a = int(a)
  86. print('Введите второе число:')
  87. b = input()
  88. while not (b.isdigit()):
  89. print('Неверный ввод')
  90. b = input("Введите число")
  91. b = int(b)
  92. v = input('Введите операцию:')
  93. while v != '+' and v != '-' and v != '*' and v != '/':
  94. print('неверный ввод')
  95. v = input('Введите операцию:')
  96.  
  97. if v == '+':
  98. r = a + b
  99. if v == '-':
  100. r = a - b
  101. if v == '/':
  102. if b == 0:
  103. print('на ноль делить нельзя')
  104. return 0
  105. r = float(a / b)
  106. if v == '*':
  107. r = a * b
  108. print('Результат =', r)
  109.  
  110.  
  111. def calc_10_2():
  112. print('Введите число в 10-ной системе счисления:')
  113. a = input()
  114. if a.isdigit():
  115. n = int(a)
  116. b = ''
  117. while n > 0:
  118. b = str(n % 2) + b
  119. n = n // 2
  120. print('Число ', a, ' в двоичной системе = ', b)
  121. else:
  122. print("Вы ввели число некорректно. Введите число еще раз: ")
  123. calc_10_2()
  124.  
  125.  
  126. def calc_10_16():
  127. print("Введите число:")
  128. num = input()
  129. from_base = 10
  130. to_base = 16
  131. if isinstance(num, str):
  132. n = int(num, from_base)
  133. else:
  134. n = int(num)
  135.  
  136. alphabet = "0123456789ABCDEF"
  137. if n < to_base:
  138. print(alphabet[n])
  139. else:
  140. b = ''
  141. z = 0
  142. x = ''
  143. while n >= to_base:
  144. z = n // 16
  145. x = n % 16
  146. b = alphabet[x] + b
  147. n = n // 16
  148. b = alphabet[n] + b
  149. print('Число в 16-ной системе счисления: ', b)
  150.  
  151.  
  152. def menu_notation():
  153. n = input('''
  154. 1. Перевод 10СИ -> 2СИ;
  155. 2. Перевод 10CB -> 16СИ;
  156. Введите действие:
  157. ''')
  158. if n.isdigit():
  159. if int(n) == 1:
  160. calc_10_2()
  161. elif int(n) == 2:
  162. calc_10_16()
  163. else:
  164. print('Вы должны ввести числа 1 или 2!', end='')
  165. menu_notation()
  166. else:
  167. print('Вы должны ввести ЧИСЛА 1 или 2!', end='')
  168. menu_notation()
  169.  
  170.  
  171. def menu_calc():
  172. tmp = 1
  173. while tmp == 1:
  174. operation = read_op()
  175. if operation == 1:
  176. calc_simple()
  177. elif operation == 2:
  178. extended_op()
  179. elif operation == 3:
  180. calc_degrees()
  181. else:
  182. menu_notation()
  183. print('Введите: 1 - чтобы продолжить работу, 2 - чтобы вернуться')
  184. tmp = input()
  185. while not('1' <= tmp <= '2'):
  186. print('неверный ввод')
  187. print('Введите: 1 - чтобы продолжить работу, 2 - чтобы вернуться')
  188. tmp = input()
  189. tmp = int(tmp)
  190.  
  191.  
Success #stdin #stdout 0.02s 9064KB
stdin
Standard input is empty
stdout
Standard output is empty