Looking for Feedback on My First Python Project: A Simple Calculator
Asked by
+StencilWork
Hey everyone! I'm 15 years old and I've just started learning Python. For my first real project, I created a simple calculator program. Here's the code I wrote:
```python
num1 = int(input("Choose a number: "))
num2 = int(input("Choose another number: ")) # selecting the numbers
operator = int(input("Choose an operator (1=+; 2=-; 3=/): "))
if operator == 1:
result = num1 + num2
elif operator == 2:
result = num1 - num2
elif operator == 3:
result = num1 / num2
print("Here is your result:", result)
```
I'm here to get some advice on this program and also looking to learn more about Python in general. If anyone has similar projects, I'd love to hear about those too! Thanks for taking the time to read this.
Answers
Congrats on your first project! Just a tip, consider formatting your code using markdown next time; it makes it a lot easier for others to read. Have you thought about what happens if the user inputs a letter instead of a number? Or what if they choose an operation that's not listed? And donโt forget to check for division by zero! Also, what's the largest and smallest number your calculator can handle?
Reply to this answer
Cool project! Also, have you considered using floats instead of integers? That way, users can input decimal numbers, which is super useful for calculations!
Reply to this answer
This is awesome! Remember, programming is all about solving problems. Focus on improving your code and fixing any bugs you find. You'll learn a lot that way! Keep it up!
Reply to this answer
Great start! You should check out Python's `eval` function; it might be a neat way to simplify your calculator logic and handle expressions more dynamically.
Reply to this answer
Nice work! If you're up for a challenge, why not try adding multiplication to your calculator? It could be a fun addition!
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions