Skip to content
Advertisement

Solved: A simple calculator to accept two numbers and print the addition, subtraction, multiplication, and division of the two numbers

Update: Re did my code. Now **I am unable to find the answer to this issue no 1). ** Newbie here. I spent the whole night trying to figure this out but I feel stuck if anyone can kindly guide me. Below is the question and Code I did for python. Thanks in advance.

  1. Limit the input range from -70 to 80 for each input number
  2. Prevent dividing by zero (Do not use try-except)
  3. Instead of hard-coding values from -70 to 80, let the user enter the range
  4. check to make sure that the lower range in < the higher range
JavaScript

Advertisement

Answer

You have not specified or put any check on the input. You can do that as shown below

JavaScript

You can reduce the counter value depending upon how many times a user is allowed to give correct input. If you would like to take input from user until they enter correct input put True in place of counter and counter2.

Both of these checks can be done in one loop also I did it this way assuming you would like to ask correct input from user as soon as they enter something invalid.

Hope this helps.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement