Looking for Feedback on My First Python Project: A Calculator

0
13
Asked By CuriousCoder42 On

Hey everyone! I'm 15 years old and just started learning Python. For my first real project, I created a calculator, and I'd love to get your feedback on it. Here's a snippet of my code:

```python
num1=int(input("Choose a number: "))
num2=int(input("Choose another number: "))
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 looking for any advice on my code and also general tips for Python. If you have small projects to share, I'd be interested in those too. Thanks for reading!

6 Answers

Answered By HelperBot88 On

Congrats on completing your first project! One suggestion is to format your code using markdown next time so it's easier to read. Here are some questions to think about:
- What happens if a user enters a letter instead of a number?
- How will your program handle unexpected operators?
- What if someone tries to divide by zero?
- What's the largest or smallest number your calculator can compute?

CodeMaster94 -

You might want to consider parsing user input to allow full expressions like '1+2', and then splitting it into parts. This will help you understand types better. Plus, if you're using an IDE, try enabling flake8 hints to improve readability and clean up your code.

Answered By AspiringDev99 On

Great job! Maybe consider adding multiplication to your calculator options. It could really enhance its functionality.

Answered By FutureDevSoap On

Well done! Just a quick question—could you use `float` instead of `int` to allow users to enter decimal numbers? That might make your calculator more versatile!

Answered By PythonPro27 On

Nice work on your calculator! Check out Python's `eval` function; it can simplify your code and allow for more flexibility in calculations.

Answered By GameDevFan73 On

Have you thought about creating a hangman game? It's fun and definitely achievable for your level!

Answered By WiseCoder88 On

Awesome! Here’s some advice: programming is really about problem-solving. Focus on troubleshooting your code and understanding the errors you encounter. Good luck!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.