feat: created initial files/comments.

This commit is contained in:
baphim
2026-10-12 10:50:19 -04:00
parent 65a790841e
commit c844467ee0
6 changed files with 33 additions and 7 deletions
+13 -7
View File
@@ -4,6 +4,8 @@ device. That is, each input to the calculator, be it a number, like 12.34 or 103
done on a separate line. After each such input, you should output to the Python console what would be displayed on your
calculator.
"""
# define a function that parses the operators tuple into actual operators and calculates result of the expression
def calc(value1, operator, value2):
if operator == "+":
@@ -21,8 +23,11 @@ def calc(value1, operator, value2):
# exits the function cleanly so result never holds None, preventing errors
return None
return result
# define global tuple of potential operators
operators = ("+", "-", "*", "/" )
# define global tuple of potential operators
operators = ("+", "-", "*", "/")
def calculate():
value1 = None
@@ -30,7 +35,9 @@ def calculate():
value2 = None
# prompts for user input, exits program if 'q' is entered
while True:
user_input = input("Enter a number, mathematic operator (+, -, *, /) or 'q' to quit: ")
user_input = input(
"Enter a number, mathematic operator (+, -, *, /) or 'q' to quit: "
)
if user_input == "q":
break
# if user inputs '=', prints message if nothing to calculate, prints 'value1' if stored
@@ -80,18 +87,17 @@ def calculate():
# Stores input as 'value1' and prints it
value1 = user_input
print(value1)
# if operator is stored, tries input for valid float value
# if operator is stored, tries input for valid float value
else:
try:
user_input = float(user_input)
# handle ValueError and print error message
# handle ValueError and print error message
except ValueError:
print("Please enter a valid number or operator")
continue
# stores input as 'value2' and prints current state of expression
value2 = user_input
print(value1, operator, value2)
calculate()
calculate()