Untitled
unknown
plain_text
3 years ago
1.3 kB
13
Indexable
from replit import clear
def operator_check()
"""Validating operator input"""
while True:
operation = input("Pick an operator: '+', '-', '*' or '/': ")
if operation != "+" and operation != "-" and operation !="*" and operation != "/":
print("Invalid input, try again")
else:
return operation
break
def calculating(first_num, second_num, operator):
"""Preforms an arithmetical operation with first two
entered argumets, based on the argument of the third parameter"""
if operator == "+":
return first_num + second_num
elif operator == "-":
return first_num - second_num
elif operator == "*":
return first_num * second_num
else:
return round(first_num / second_num, 2)
again = False
while True:
if again == False:
first_number = float(input("Enter the first number: "))
else:
first_number = result
operation = operator_check()
second_number = float(input("Enter the second number: "))
result = calculating(first_number, second_number, operation)
print(f"{first_number} {operation} {second_number} = {result}")
new_calc = input(f"Type 'y' to continue calculating with {result}, or type 'n' to start a new calculation: ")
if new_calc == "y":
again = True
elif new_calc == "n":
clear()Editor is loading...