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

Rapid_tv

🔹 Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. 👉 Rules: 🔹 Code Example 🔹 Example Run 🔹 Concepts Learned…

Read more

VOD-ZalHD

🔹 Introduction The Number Guessing Game is a classic beginner Python project. 🔹 Code Example 🔹 Example Run 🔹 Concepts Learned 🔹 Summary ⬇️ Download VOD-ZalHD تحميل Server 1 ⬇️…

Read more

Delux_pro

🔹 Introduction The To-Do List App is one of the most popular beginner projects. It teaches you how to: 🔹 Code Example 🔹 Features of This App 🔹 Example Run…

Read more

Fam4k

🔰 Project Overview A calculator is one of the simplest yet most effective projects to start with in Python.You will learn: ✍️ Step 1: Plan the Calculator We need: 🖥️…

Read more

Speed_HD+

1. Introduction Data visualization helps us understand patterns and insights in data by converting raw numbers into charts and graphs.In Python, the most popular libraries are: 2. Installing Required Libraries…

Read more

Dauo

1. Introduction Web scraping is the process of extracting data from websites. In Python, we commonly use libraries like requests (to fetch web pages) and BeautifulSoup (to parse and extract…

Read more