GO_tv

🔰 Introduction :

The current image has no alternative text. The file name is: PMPM.jpg

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

Related Posts

FivG_Pro

🔰 What Is a Function? A function is a reusable block of code that performs a specific task.Instead of repeating code, we can write it once and call it whenever…

Read more

Show7_Pro

🟢 Lesson 6 – Intermediate Level 🔰 What Is a Module? A module is simply a Python file (.py) containing code (functions, variables, classes) you can reuse in other programs….

Read more

GoldiptvPro

🟢 Lesson 5 – Intermediate Level 🔰 What Are Exceptions? An exception is an error that occurs during the execution of a program.If not handled, it will stop the program…

Read more

Domingo

🟢 Lesson 4 🔰 What Is OOP? Object-Oriented Programming (OOP) is a programming style where you organize code into objects that contain: Python supports OOP using: 🧱 Example: Why Use…

Read more

SHARK_PRO

🔰 What Is File Handling? 🟢 Lesson 3 File handling lets your Python programs interact with files on your computer — read data from them or save data to them….

Read more

ZinaTv

🟢 Lesson 2 – Intermediate Level 🔹 Python Dictionaries: Storing and Accessing Key-Value Data 🔰 What Is a Dictionary? A dictionary in Python is a data structure that stores data…

Read more