Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2d345cb

Browse files
Initial commit.
0 parents commit 2d345cb

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

‎Beginner/1_calculator.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Function to validate the user's numeric input
2+
def get_number(prompt):
3+
while True:
4+
# Get the user's input
5+
user_input = input(prompt)
6+
# Use a try block to catch errors during float conversion
7+
try:
8+
return float(user_input) # Try converting input to a float
9+
except ValueError:
10+
print("Invalid input. Please enter a valid number.")
11+
12+
# Get and validate user input for the first and second numbers
13+
number1 = get_number("Please enter the first number: ")
14+
number2 = get_number("Please enter the second number: ")
15+
16+
# List the valid operations
17+
valid_operations = ["add", "subtract", "multiply", "divide"]
18+
while True:
19+
# Get the user's operation input
20+
operation = input("Choose an operation (add, subtract, multiply, divide): ").lower()
21+
# Check if it's valid
22+
if operation in valid_operations:
23+
break
24+
else:
25+
# Invalid operation error
26+
print("Invalid operation. Please choose one of the following: add, subtract, multiply, divide.")
27+
28+
# Perform the chosen operation using if checks and store it for later
29+
if operation == "add":
30+
result = number1 + number2
31+
elif operation == "subtract":
32+
result = number1 - number2
33+
elif operation == "multiply":
34+
result = number1 * number2
35+
elif operation == "divide":
36+
# Handle division by zero
37+
if number2 != 0:
38+
result = number1 / number2
39+
else:
40+
result = "undefined (cannot divide by zero)"
41+
42+
# Display the result
43+
print(f"The result of {operation}ing {number1} and {number2} is: {result}")

‎LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Infinitode Pty Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Python Projects
2+
3+
An open-source GitHub repository containing Python project ideas, steps, tips, and code solutions.
4+
5+
This repository is designed to help Python learners at all levels, starting with beginner-friendly projects and gradually progressing to more advanced ones. Each project includes clear instructions and a working code implementation.
6+
7+
## Table of Contents
8+
1. [Setup](#setup)
9+
2. [Beginner Projects](#beginner-projects)
10+
3. [Contributing](#contributing)
11+
4. [License](#license)
12+
13+
## Setup
14+
15+
- Make sure that you have at least Python `3.6` or later (we recommend `3.12`) installed on your computer. You can do a quick search and download it from a trusted provider for your platform.
16+
17+
- Make sure that you have an IDE, or a place where you could code and run the Python interpreter.
18+
> [!TIP]
19+
> We use Visual Studio Code. It's fast, efficient, and has many extensions and customizability options.
20+
21+
## Beginner Projects
22+
These projects are ideal for those new to Python. Each project includes a description, steps to follow, and tips for completing it.
23+
24+
### 1. Calculator
25+
- **Description**: Build a simple calculator that performs basic arithmetic operations (`+`, `-`, `*`, `/`).
26+
27+
- **Steps**:
28+
1. Prompt the user for two numbers and an operator.
29+
2. Perform the chosen operation.
30+
3. Display the result.
31+
32+
- **Tips:**
33+
34+
</summary>
35+
<details><summary>Tip 1:</summary>
36+
37+
Use `input()` to get the user's input.
38+
39+
> [!TIP]
40+
> Learn more from here: https://docs.python.org/3/library/functions.html#input
41+
42+
</details>
43+
<details><summary>Tip 2:</summary>
44+
45+
Use `variables` to store the user's input.
46+
47+
</details>
48+
<details><summary>Tip 3:</summary>
49+
50+
Use `conditional` statements to check for valid values, and perform certain operations.
51+
52+
> [!TIP]
53+
> Learn more from here: https://www.w3schools.com/python/python_conditions.asp
54+
55+
</details>
56+
<details><summary>Tip 4:</summary>
57+
58+
Print out the result using `print()`.
59+
60+
> [!TIP]
61+
> Learn more from here: https://docs.python.org/3/library/functions.html#print
62+
63+
</details>
64+
65+
Working code solutions can be found in the `/Beginner` folder.
66+
67+
---
68+
69+
## Contributing
70+
Contributions are welcome! If you have project ideas or improvements, feel free to fork the repository and open a pull request.
71+
72+
---
73+
74+
## License
75+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /