# Input two numbers
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Calculate the sum
result = num1 + num2
# Display the result
print("The sum of", num1, "and", num2, "is:", result)
This is a simple calculation code using python, and now I am goind to expanded it.
print("Welcome to calculate web!")
#This is a hello sentence
while True:
options = """
Desired operation
(1) add
(2) subtract
(3) multiply
(4) divide
"""
#I made four option to show users options
print(options)
#Print the option
option = int(input("Choice a operation: "))
#Ask users which one
if option == 1:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
add = int(num1) + int(num2)
print(f"The result is {add}")
#This if block is when user choose option 1 and I ask users two number they want and add it then I print it
elif option == 2:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
subtract = int(num1) - int(num2)
print(f"The result is {subtract}")
#This elif block is when user choose option 2 and I ask users two number they want and subtract it then I print it
elif option == 3:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
multiply = int(num1) * int(num2)
print(f"The result is {multiply}")
#This elif block is when user choose option 3 and I ask users two number they want and multiply it then I print it
elif option == 4:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
divide = int(num1) / int(num2)
print(f"The result is {divide}")\
#This elif block is when user choose option 4 and I ask users two number they want and divide it then I print it
keep_calculate = input("Would you like to perform another calculation? (y/n) ")
if keep_calculate != "y":
break
#I ask users if they want to keep going or not, if their answer isn't "y" then program stop