Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/setupCheck.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions src/function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from main import main

def ask_user_input():

global operand1
# Get first operand from the user
operand1 = float(input("Enter the first operand: "))

global operator
# Get the operator from the user
operator = input("Enter an operator (+, -, *, /): ")

global operand2
# Get second operand from the user
operand2 = float(input("Enter the second operand: "))

return operand1, operator, operand2

def calculate(ope1, oper, ope2):
# Perform the operation based on the operator
res = None
match operator:
case '+':
res = (operand1 + operand2)

case '-':
res = (operand1 - operand2)

case '*':
res = (operand1 * operand2)

case '/':
if ope2 == 0:
print("Error: Division by zero is undefined.")
return
res = (ope1 / ope2)

case _:
print("Error: Operator '{}' not recognized.".format(operator))
return

return res

def display_result(ope1, oper, ope2, res):
print(f"{ope1} {oper} {ope2}={res}")



56 changes: 40 additions & 16 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,56 @@


def main():
ask_user_input()
global result
result = calculate(operand1, operator, operand2)
display_result(operand1, operator, operand2, result)

def ask_user_input():

global operand1
# Get first operand from the user
operand1 = float(input("Enter the first operand: "))

global operator
# Get the operator from the user
operator = input("Enter an operator (+, -, *, /): ")

global operand2
# Get second operand from the user
operand2 = float(input("Enter the second operand: "))

return operand1, operator, operand2

def calculate(ope1, oper, ope2):
# Perform the operation based on the operator
if operator == '+':
result = operand1 + operand2
elif operator == '-':
result = operand1 - operand2
elif operator == '*':
result = operand1 * operand2
elif operator == '/':
if operand2 == 0:
print("Error: Division by zero is undefined.")
res = None
match operator:
case '+':
res = (operand1 + operand2)

case '-':
res = (operand1 - operand2)

case '*':
res = (operand1 * operand2)

case '/':
if ope2 == 0:
print("Error: Division by zero is undefined.")
return
res = (ope1 / ope2)

case _:
print("Error: Operator '{}' not recognized.".format(operator))
return
result = operand1 / operand2
else:
print("Invalid operator.")
return

# Print the result
print("Result:", result)
return res

def display_result(ope1, oper, ope2, res):
print(f"{ope1}' '{oper}' '{ope2}'='{res}")

# Call the main function to run the program
main()
main()