Skip to main content
ALPHA    This is new software undergoing tests! Thank you for your patience.

Candidate: Ezra Ezra Assessed by: Nicholas Tollervey ntoll

Python (2023) ~ Grade 1 (Initial)

A simple calculator

This application uses simple functions to do basic arithmetic(addition, subtraction, multiplication and division) based on the selections of the user. This project is built for people who do simple mathematical calculations. It only works with two numbers. when the app is launched (i.e python <filename>), the user is presented with a couple of choices to make based on what he wants to do with application. When the choice is made, the app will the ask for the numbers involved and do the math for you.

Status: Submitted for assessment.


Ezra Ezra ~ 23 Nov 2022 4:22 a.m. (updated: 28 Nov 2022 12:57 a.m.)

operator = input(f""" select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide 
: """)

# check the operator value and perform the operation 

if operator == 'Add' or operator == 'add' or operator == '+':
    num1 = float(input("Enter first number: "))
    num2 = int(input("Enter second number: "))
    add = num1 + num2
    print(add)

elif operator == 'Subtract' or operator == "subtract" or operator == '-':
    num1 = float(input("Enter first number: "))
    num2 = int(input("Enter second number: "))
    minus = num1 - num2
    print(minus)

elif operator == 'Multiply' or operator == 'multiply' or operator == '*':
    num1 = float(input("Enter first number: "))
    num2 = int(input("Enter second number: "))
    product = num1 * num2
    print(product)

elif operator == 'Divide' or operator == 'divide' or operator == '/':
    num1 = float(input("Enter first number: "))
    num2 = int(input("Enter second number: "))
    div = num1 / num2
    print(div)

else:
    print("Invalid input")

ntoll Nicholas Tollervey ~ 23 Nov 2022 3:13 p.m.

Hi Ezra,

Thank you so much for submitting your code and I'm looking forward to working with you to improve your project.

Before we continue there are some things you need to either change or add - so I have all the things I need to be able to assess your work and help you grow as a developer.

Please can you make the following changes and additions:

```python
<your code goes here>
```

Once these things are updated, we'll be in a good place to review, refine and revise your project into a version that reflects your current level of coding, and which I can use as the basis of my final assessment.

Many thanks in advance..!


ntoll Nicholas Tollervey ~ 24 Nov 2022 2:33 p.m.

Hi Ezra,

I also just wanted to let you know that adding my first comment to your project highlighted a couple of bugs in the CodeGrades website. I've since fixed them, but I wanted to say thank you..! I'm looking forward to your revised version of the project. I'll get alerts when you add comments here so I'll be able to see you make the requested changes. 👍


ntoll Nicholas Tollervey ~ 04 Dec 2022 11:34 a.m. (updated: 04 Dec 2022 11:41 a.m.)

Dear Ezra,

Thank you for updating your code. It looks so much better.

I've just run your project and it works! 👍 I even tried to use it in not-very-friendly ways, and it recovered well 🤣 :

$ python calc.py 
 select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide 
: 5
Invalid input

$ python calc.py 
 select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide 
: sausages
Invalid input

But I also got some unexpected behaviour.

For example, the opening "menu" of operations looks like a list, and I wanted to add two numbers, so typed 1 (since that was the item number, for addition):

$ python calc.py 
 select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide 
: 1
Invalid input

I had to look at the code to work out why it wasn't a valid input. If I were not a technical user, I'm not sure I'd understand why 1 was invalid input. How might you make this easier for a non-technical user?

...and then I found this bug. The project crashed with an error:

$ python calc.py 
 select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide 
: add
Enter first number: 1
Enter second number: 2.5
Traceback (most recent call last):
  File "/home/ntoll/src/scratch/codegrades/ezra/calc.py", line 12, in <module>
    num2 = int(input("Enter second number: "))
ValueError: invalid literal for int() with base 10: '2.5'

Can you investigate this, explain what went wrong, and fix it please..? 👍

I also accidentally hit return twice, while entering the numbers, and the project crashed. Could these two bugs be related..?

$ python calc.py 
 select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide 
: add
Enter first number: 3
Enter second number: 
Traceback (most recent call last):
  File "/home/ntoll/src/scratch/codegrades/ezra/calc.py", line 12, in <module>
    num2 = int(input("Enter second number: "))
ValueError: invalid literal for int() with base 10: ''

I have a feature request too... currently I can only operate on two numbers. What if I want to add, say, a whole list of numbers...? How might you do that..? (And if this isn't clear, have a look around the Internet, investigate possible solutions and just ask... remember I'm here to help, and asking questions or pointing out where and why you're stuck on a problem is a good thing - since it shows evidence of engaging with and growing through a problem 📈. The only wrong question, is the question you don't ask. 😄 )

I have some comments about the code:

Please don't be disheartened by the level of detail or amount of feedback I'm giving... this is to be expected and reflects the good start you've made to the project. Of course, CodeGrades is all about learning with a mentor, and so my suggestions, questions and requests for updates are part of this process. 👍

One final (and very important) thing. You have submitted your project for grade 3. The project, as it currently stands, is at around a grade 1 level. I think, after we collaborate on the project, it could be a strong grade 2 level. But to get this project to a grade 3 level would take a significant amount of work.

I'm conscientious that I don't want you to find yourself in a situation where the wonderful work you've been doing is being measured against too high a standard of grading. To put this into perspective... when I was at PyCon Ghana 🇬🇭 I learned to play Oware and managed to buy a board. Clearly, it would be rather disheartening to practice playing with an Oware grand-master (too high a level)... so far better to play against folks at the right level for me. Similarly, I think it would be much better for you if we adjusted the grade to grade 2 (I can do this, as an admin user of CodeGrades).

What do you think..? Do let me know..!

The most important thing is the CodeGrades process helps and supports you in your learning journey to experience, rather than makes you feel disheartened.

Of course, once you have worked towards your grade 2, then grade 3 will become much easier to do (rather than starting from grade 3). And since you're an alpha tester of CodeGrades, all your grading will be free anyway..! 😉

I've had a lot of fun trying our your project, especially when I was trying to break it in interesting ways (it's very resilient code!).

In summary, you have several things to do:

I'm looking forward to seeing how you get on, and (one final reminder) I'm here to help, so just ask questions via this project (such interactions are important evidence for the assessment and will show others how you positively engage with coding). 🚀

Best of luck..! 👍


ntoll Nicholas Tollervey ~ 04 Dec 2022 11:49 a.m.

One more thing... when you've revised your code, add it here as a new comment. That way it becomes clear how your project has evolved and improved. 🚀


Ezra Ezra ~ 27 Dec 2022 1:08 a.m. (updated: 27 Dec 2022 1:10 a.m.)

operator = input(f""" select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide 
: """)

num1 = float(input("Enter first number: "))
num2 = int(input("Enter second number: "))

# check the operator value and perform the operation 

if operator in [ 'Add', 'add', '+','1']:
    add = num1 + num2
    print(add)

elif operator in ['Subtract','subtract','2' ,'-']:
    minus = num1 - num2
    print(minus)

elif operator in ['Multiply','multiply','*','3']:
    product = num1 * num2
    print(product)

elif operator in ['Divide','divide','/','4']:
    div = num1 / num2
    print(div)

else:
    print("Invalid input")

Ezra Ezra ~ 27 Dec 2022 1:12 a.m.

please am still working on how to work with more than two numbers. I am done with the addition but am facing challenges with the other operators.


Ezra Ezra ~ 27 Dec 2022 1:38 a.m.

operator = input(f""" select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide 
: """)

numbers = input("Enter numbers: ")
data = list(map(float, numbers.split()))

# check the operator value and perform the operation 

if operator in [ 'Add', 'add', '+','1']:
    diff = data[0]
    for i in range(1,len(data)):
        diff = diff + data[i]
    print(diff)

elif operator in ['Subtract','subtract','2' ,'-']:
    diff = data[0]
    for i in range(1,len(data)):
        diff = diff - data[i]
    print(diff)

elif operator in ['Multiply','multiply','*','3']:
    diff = data[0]
    for i in range(1,len(data)):
        diff = diff * data[i]
    print(diff)

elif operator in ['Divide','divide','/','4']:
    diff = data[0]
    for i in range(1,len(data)):
        diff = diff / data[i]
    print(diff)


else:
    print("Invalid input")

ntoll Nicholas Tollervey ~ 03 Jan 2023 4:14 p.m.

Ezra,

Happy new year 🎉, and thank you for your updates. The project is definitely moving forward, and please keep up the good work.

First of all, I've changed the level for your grade to grade 1, since this is more closely aligned to the code you've written and the feedback you'll get as a result will be more useful for you. The URL for your grade is now: https://www.codegrades.com/user/Ezra/python2023/grade1/

I have read your code and have some updates for you to think about:

 select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide
: 1
Enter numbers: 1, 2, 3, 4
Traceback (most recent call last):
  File "/home/ntoll/mu_code/ezra.py", line 10, in <module>
    data = list(map(float, numbers.split()))
ValueError: could not convert string to float: '1,'

I realise the problem is of my own making, but when you ask the user to enter number could you perhaps explain what form they should take (for example, Enter numbers (separated by a space):)

 select operation from below
1. Add
2. Subtract
3. Multiply
4. Divide
: ADD
Enter numbers: 1 2 3
Invalid input

I think you'd find this article about the lower method helpful in coming up with a solution... especially the bit at the end.

result = 0
for number in data:
    result = result + number

I hope you agree that for number in data is much easier to read and understand than for i in range(1, len(data)). It's also more idiomatic to write it this way (the other way, being the classic C-ish way to do things, which is why I understand why you're doing it!)

As always Ezra, I'm here to help, so please don't hesitate to ask questions or seek guidance. It's yet more evidence that you're pro-actively engaging in the grading process, so don't hold back. I think, if you address the points I've just raised, I'll be in a position to assess your project and give you your mark and feedback. 🚀


Back to top