46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
def main():
|
|
print("Welcome to the Calculator")
|
|
command = input("Select command: + or *\nType exit if u want exit \n")
|
|
match command:
|
|
case "+":
|
|
summ()
|
|
main()
|
|
case "*":
|
|
multiplication()
|
|
main()
|
|
case "exit":
|
|
exit
|
|
case _:
|
|
print(KeyError("Incorrect"))
|
|
main()
|
|
def summ():
|
|
print("Enter number to sum, enter space to finish")
|
|
total = 0
|
|
while True:
|
|
num_input = input()
|
|
if num_input == " ":
|
|
print (total)
|
|
main()
|
|
try:
|
|
number = float(num_input)
|
|
total += number
|
|
print(f"Total summ = {total}")
|
|
except ValueError:
|
|
print("Error, enter correct number")
|
|
def multiplication():
|
|
print("Enter number to multiplication, enter space to finish")
|
|
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()
|