Python Forum
while loop on a calculator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while loop on a calculator
#4
char.lower() returns the text of char in lower case. This allows you to test against 'q' and 'Q' with one test. This gets past this problem:

while char != 'Q' or 'q':
which is a misuse of the 'or' operator. It is equivalent to:

while (char != 'Q') or 'q':
Since non-empty strings evaluate as True, 'q' is always True and the loop condition is always True.

Also, break can't be used outside of a loop, that's why it was working for you.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
while loop on a calculator - by missus_brown - Feb-10-2019, 05:57 PM
RE: while loop on a calculator - by Larz60+ - Feb-10-2019, 06:21 PM
RE: while loop on a calculator - by missus_brown - Feb-10-2019, 06:41 PM
RE: while loop on a calculator - by ichabod801 - Feb-10-2019, 08:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calculator Loop Help dock1926 3 3,819 Jun-23-2021, 10:05 PM
Last Post: HereweareSwole
  Python calculator help but not using while loop with true, any flags variable ,break kirt6405 13 5,625 Jun-08-2021, 06:39 AM
Last Post: Larz60+
  Weight loss calculator loop error drogers10940 7 14,427 Feb-14-2021, 12:36 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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