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

FlyFeditv

📘 Introduction In this project, you’ll create a command-line Expense Tracker that allows users to: ✅ Add expenses with category, amount, and description✅ View total spending and category breakdown✅ Automatically…

Read more

NetCinFly

📘 Introduction In this project, you’ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

🌐 Introduction In this project, you’ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.You’ll use the BeautifulSoup and Requests libraries to…

Read more

Cobra_Pro

🌦️ Introduction In this project, you’ll build a Weather App in Python that retrieves live weather information from an online API.You’ll learn how to work with HTTP requests, JSON data,…

Read more

Show7-Pro

Concepts Covered: 🎯 Objective: Create a simple, text-based contact book application that allows users to: 💡 Code (contact_book.py): 🧠 Example Usage Console Output Example: 💾 Notes ⬇️ Download Show7-Pro تحميل…

Read more

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