Python Forum
Need suggested alterations (6 function calculator)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need suggested alterations (6 function calculator)
#3
(Nov-08-2016, 04:12 PM)nilamo Wrote: A while loop doesn't make sense, because you only ever want the block to run once, AND you're not changing any of the conditions, so it'd be an infinite loop (if not for the "break").

And your condition can be phrased using english to say "if either integer1 or interger2 is less than or equal to 13, it's invalid".  Based on your text, that doesn't sound right.  Maybe you should be using >=13 instead of <=13?

Also, mixing and/or like that can lead to some confusion.  Once you have complicated conditions like that, you should use parenthases to make absolutely certain what you expect to happen is actually happening.  Because AND has higher precidence than OR, what you have now is the same as this:
if (integer1 <= 0 and integer1 <= 13) or (integer2 <= 0 and integer2 <= 13):
Also (pt 2), an int will never be negative.  Checking to see if it's negative is... a waste of your typing time :p

Thanks for the reply, I've been trying to rewrite that whole line but still am having no luck. I can only use #'s 1-12 on the input and must produce invalid input if not. Also on the math operations the same thing, if a invalid choice is chosen, produce invalid choice. Also what is the keyword for terminating a whole program, or is there one. Is this where loops come in?

All my sample runs work except #2

Sample run 1:
This program will perform basic arithmetic operations on two integers between 1 and 12.
Enter an int between 1 $ 12: 2
Enter an int between 1 $ 12: 3
(A)ddition
(S)ubtraction
(M)ultiplication
(D)ivision
®emainder
(E)xponentiation
e
2 ^ 3 = 8



Sample run 2:
This program will perform basic arithmetic operations on two integers between 1 and 12.
Enter an int between 1 $ 12: 3
Enter an int between 1 $ 12: 15
Invalid Choice


Sample run 3:
This program will perform basic arithmetic operations on two integers between 1 and 12.
Enter an int between 1 $ 12: 3
Enter an int between 1 $ 12: 6
(A)ddition
(S)ubtraction
(M)ultiplication
(D)ivision
®emainder
(E)xponentiation
g
Invalid Choice

Sample run 4:
This program will perform basic arithmetic operations on two integers between 1 and 12.
Enter an int between 1 $ 12: 9
Enter an int between 1 $ 12: 3
(A)ddition
(S)ubtraction
(M)ultiplication
(D)ivision
®emainder
(E)xponentiation
d
9 / 3 = 3.0
Reply


Messages In This Thread
RE: Need suggested alterations (6 function calculator) - by EwH006 - Nov-08-2016, 05:15 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020