Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if var is "string"
#1
In this code, what's the difference between my first three conditionals and the 4th one (elif size is "a":)? They all look like the same type of if statement to me!

S = 0
M = 0
L = 0
while True:
    size = input("Select a pizza size (small, medium, large): \n")
    if size is "small":
        S += 1
    elif size is "medium":
        M += 1
    elif size is "large":
        L += 1
    elif size is "a":
        print("wth?")
        break
    else:
        print("That's not a pizza size")
    break
Reply
#2
You need to change all the 'is' to ==
if size == "small"
is checks object identity
== checks for equality
Reply


Forum Jump:

User Panel Messages

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