🔰 Introduction :

Congratulations! You’ve reached the end of the basic learning series.
In this lesson, you’ll create a real-world program that uses:
Variables
Conditions (if/else)
While loops
Functions
Input and output
The goal is to build a calculator that allows the user to perform operations: addition, subtraction, multiplication, and division — and repeat until they choose to exit.
🧩 Requirements :
Display a list of options.
Perform the operation as desired by the user.
Repeat the query until they type “exit.”
Handle division by zero safely.
✅ Expected final program format :
ruby
Choose an operation:
1 – Addition
2 – Subtraction
3 – Multiplication
4 – Division
5 – Exit
1
Enter the first number: 10
Enter the second number: 5
Result: 15
🧑💻 Full code:
python
def add(a, b):
return a + b
def subtract(a, b):
return a – b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
return “Cannot divide by zero!”
return a / b
while True :
print(“\nChoose an operation:”)
print(“1 – Addition”)
print(“2 – Subtraction”)
print(“3 – Multiplication”)
print(“4 – Division”)
print(“5 – Exit”)
choice = input(“>> “)
if choice == “5”:
print(“✅ Exited the calculator. Thank you for using the program!”)
break
if choice not in [“1”, “2”, “3”, “4”]:
print(“❌ Invalid choice. Try again.”)
continue
try:
num1 = float(input(“Enter the first number: “))
num2 = float(input(“Enter the second number: “))
except ValueError:
print(“⚠️ Enter only integers!”)
continue
if choice == “1”:
result = add(num1, num2)
elif choice == “2”:
result = subtract(num1, num2)
elif choice == “3”:
result = multiply(num1, num2)
elif choice == “4”:
result = divide(num1, num2)
print(“🔢 Result:”, result)
🧠 Ideas for future program development :
Support operations using symbols (+, -, *, /).
Add a log of previous operations.
Support graphical interfaces using a library like tkinter.
Use lists to store results.
📝 Conclusion :
Congratulations! Now you can:
Read data from the user
Implement logical conditions
Repeat commands
Organize code using functions
And build a real project
⬇️ Download GO_tv تحميل server 1 ⬇️ Download GO_tv تحميل server 2