60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
def main():
|
|
print("Welcome to the Calculator")
|
|
command = input("Select command: [ + ] [ - ] [ * ] [ / ] \nType exit if u want exit \n")
|
|
match command:
|
|
case "+":
|
|
summ()
|
|
case "*":
|
|
multiplication()
|
|
case "minus":
|
|
minus()
|
|
case "exit":
|
|
exit
|
|
case _:
|
|
print(KeyError("Incorrect"))
|
|
main()
|
|
def summ():
|
|
print("Enter number(s) to sum, enter space to calculate")
|
|
total = 0
|
|
while True:
|
|
num_input = input()
|
|
if num_input == " ":
|
|
print (f"Total summ = {total}")
|
|
main()
|
|
try:
|
|
number = float(num_input)
|
|
total += number
|
|
print(f"Total summ = {total}")
|
|
except ValueError:
|
|
print("Error, enter correct number")
|
|
def minus():
|
|
print("Enter number(s) to minus, enter spase to calculate")
|
|
total = 0
|
|
while True:
|
|
num_input = input()
|
|
if num_input == " ":
|
|
print(total)
|
|
main()
|
|
try:
|
|
number = float(num_input)
|
|
total -= number
|
|
print(f"Total minus = {total}")
|
|
except ValueError:
|
|
print("Error, enter correct number")
|
|
def multiplication():
|
|
print("Enter number to multiplication, enter space to calculate")
|
|
total = 0
|
|
while True:
|
|
num_input = input()
|
|
if num_input == " ":
|
|
print (total)
|
|
main()
|
|
try:
|
|
number = float(num_input)
|
|
total *= number
|
|
print(f"Total multiplication = {total}")
|
|
except ValueError:
|
|
print("Error, enter correct number")
|
|
if __name__ == "__main__":
|
|
main()
|