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"ENDPYTHON 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.
0 likes · 111 views · Jan 1, 2025
A Python-based calculator implementing basic arithmetic operations (addition, subtraction, multiplication, division) using pseudocode for logic.