I can't figure out what I am doing wrong. I have tried using a break, and tried setting what the variable !=, I am doing this on cengage and it is very finnicky.
""" LeftOrRight.py - This program calculates the total number of left-handed and right-handed students in a class. Input: L for left-handed; R for right handed; X to quit. Output: Prints the number of left-handed students and the number of right-handed students."""
rightTotal = 0 # Number of right-handed students.
leftTotal = 0 # Number of left-handed students.
leftOrRight = input("Enter an L if you are left-handed,a R if you are right-handed or X to quit.")
while leftOrRight != "X":
print (leftOrRight)
if leftOrRight == "L":
leftTotal = (leftTotal + 1)
elif leftOrRight == "R":
rightTotal = (rightTotal + 1)
else:
break
print("Number of left-handed students: " + str(leftTotal))
print("Number of right-handed students: " + str(rightTotal))
According to your code you are not changing the value for leftOrRight after entering the loop so the condition for your while loop is never false I would suggest the following edit:
so that you get a prompt every time the loop is executed and you can click X to exit
your
input()
is outside thewhile
loop, soleftOrRight
never changes, never get toX
so it will not exit the loop:Your program just got the character that had the largest id in the ascii table.
And only doing the first string as the
longString = max(n)
wasn't even in the while loop.also max returns the largest value, so in this case it was just converting the text into an ascii number.
instead you should use
len(string)
which returns the length of the string.Unlike
max()
which is used like:11 == max(11,10,1,2)
as 11 is the largest character.