Вчера начал изучать Python. Оцените пожалуйста код:
import math
from operator import *
#Functions for the calculating
def calc():
select = input("Select an operator: + - * / ** √\n")
operators = ["+", "-", "*", "/", "**"]
try:
if select == "√":
root = float(input("Enter a number..."))
print("√", root,"=", math.sqrt(root))
elif select in operators:
num1 = float(input("Enter the first number...\n"))
num2 = float(input("Enter the second number...\n"))
if select == "+":
print(num1, "+",num2,"=", add(num1, num2))
elif select == "-":
print(num1, "-",num2,"=", sub(num1, num2))
elif select == "*":
print(num1, "*",num2,"=", mul(num1, num2))
elif select == "/":
print(num1, "/",num2,"=", div(num1, num2))
elif select == "**":
print(num1, "**",num2,"=", pow(num1, num2))
else:
print("Error, invalid input")
except:
print("Error, you need to enter a number")
#The main function which use a while loop
def main():
i = 0
while True:
if i == 0:
calc()
#print('\nCalculation finished. Do another? (Y/N)')
selector = input("Calculation finished. Do another? (Y/N)\n")
if selector.lower() == 'n':
break
elif selector.lower() == 'y':
calc()
i = 1
#About the script, here I use the main function
print("This is a simple calculator on python")
main()
Буду благодарен за любую критику!