Beginner Python Projects - Calculator, Prime Checker
This is a command-line calculator that allows users to perform unlimited arithmetic operations interactively. It supports addition, subtraction, multiplication, and division with proper error handling, including division by zero and invalid input.
- Continuous calculation loop until user quits
- Handles:
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Input validation for both numbers and operations
- User-friendly prompts and feedback
- Make sure you have Python installed (
python --version
). - Save the code in a file, e.g.,
calculator.py
. - Run the script:
๐งฎ Welcome to the Continuous Python Calculator! Operations: + for Add | - for Subtract | * for Multiply | / for Divide | q to Quit
Choose operation (+, -, *, /) or 'q' to quit: + Enter first number: 5 Enter second number: 3 Result: 8.0
Choose operation (+, -, *, /) or 'q' to quit: / Enter first number: 10 Enter second number: 0 Result: Error: Cannot divide by zero.
Choose operation (+, -, *, /) or 'q' to quit: q โ Calculator closed. Thank you!
This Python script checks whether a number is a prime, lists all prime numbers from 1 to the given number, and also finds twin prime pairs in that range.
- โ Checks if the entered number is a prime number
- ๐ Lists all prime numbers from 1 to the entered number
- ๐งช Identifies and prints twin prime pairs
(Twin primes are pairs of prime numbers that differ by exactly 2, e.g., (3, 5), (11, 13))
- Make sure Python is installed. Run
python --version
to check. - Save the script as
prime_checker.py
. - Run the script in your terminal:
Enter The Number: 20 No It is not a Prime Number The Prime Numbers from 1 to 20 are: 2 3 5 7 11 13 17 19 Total Prime Numbers From 1 to 20 are: 8 The Twin Prime Numbers From 1 to 20 are: [3, 5] [5, 7] [11, 13] [17, 19]