Basic Calculator - Python Program (Pseudocode Implementation)

Khan mirza

0

Data Scientist

Prompt Writer

Python and Psuedocode

Adobe Acrobat

PyQt

This project demonstrates a basic calculator built with Python. Using the pseudocode I created, the program performs fundamental arithmetic operations such as addition, subtraction, multiplication, and division. It prompts the user for input, processes the data, and displays the result. The calculator continues to function until the user decides to exit. This project highlights my ability to translate pseudocode into a working Python application.

PSEUDOCODE:

BEGIN
DISPLAY "Welcome to the Calculator!"
REPEAT
DISPLAY "Select an operation:"
DISPLAY "1. Addition"
DISPLAY "2. Subtraction"
DISPLAY "3. Multiplication"
DISPLAY "4. Division"
DISPLAY "5. Exit"
INPUT choice
IF choice == 5 THEN
DISPLAY "Exiting calculator. Goodbye!"
BREAK
END IF
DISPLAY "Enter the first number:"
INPUT num1
DISPLAY "Enter the second number:"
INPUT num2
IF choice == 1 THEN
result = num1 + num2
DISPLAY "The result is: " + result
ELSE IF choice == 2 THEN
result = num1 - num2
DISPLAY "The result is: " + result
ELSE IF choice == 3 THEN
result = num1 * num2
DISPLAY "The result is: " + result
ELSE IF choice == 4 THEN
IF num2 == 0 THEN
DISPLAY "Error! Division by zero is not allowed."
ELSE
result = num1 / num2
DISPLAY "The result is: " + result
END IF
ELSE
DISPLAY "Invalid choice. Please select a valid operation."
END IF
DISPLAY "Do you want to perform another calculation? (yes/no)"
INPUT answer
UNTIL answer == "no"
END

PYTHON CODE:

while True:
# Display menu and take user input
print("Select an operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exit")
choice = int(input("Enter your choice: "))
if choice == 5:
print("Exiting calculator. Goodbye!")
break
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
if choice == 1:
result = num1 + num2
print(f"The result is: {result}")
elif choice == 2:
result = num1 - num2
print(f"The result is: {result}")
elif choice == 3:
result = num1 * num2
print(f"The result is: {result}")
elif choice == 4:
if num2 == 0:
print("Error! Division by zero is not allowed.")
else:
result = num1 / num2
print(f"The result is: {result}")
else:
print("Invalid choice. Please select a valid operation.")
# Option to continue or exit
answer = input("Do you want to perform another calculation? (yes/no): ").lower()
if answer == "no":
break
Screenshot of the coding process.
Screenshot of the coding process.
Like this project
0

Posted Jan 1, 2025

A Python-based calculator implementing basic arithmetic operations (addition, subtraction, multiplication, division) using pseudocode for logic.

Likes

0

Views

51

Tags

Data Scientist

Prompt Writer

Python and Psuedocode

Adobe Acrobat

PyQt

Content Editing/Writing Project – Before & After Example.
Content Editing/Writing Project – Before & After Example.
Lens & Light Photography: Premium Minimalist Logo Design
Lens & Light Photography: Premium Minimalist Logo Design