-2

This is the source site i cant get to understand this piece of code, what does "While not name:" refers to and as mentioned here how could it be same as "not name != '' and how "numOfGuests != 0 " is as same as "if numOfGuests:" your help would be appriciated

name = ''
while not name: #(1)
    print('Enter your name:')
    name = input()
print('How many guests will you have?')
numOfGuests = int(input())
if numOfGuests: #(2)
    print('Be sure to have enough room for all your guests.') #(3)
print('Done')
Unknown
  • 1
  • 2
  • See [*truth value testing*](https://docs.python.org/3/library/stdtypes.html#truth-value-testing). The empty string and integer 0 are both false values. – Martijn Pieters Apr 28 '19 at 09:23

1 Answers1

-1

In python,the null value means False and Non-null value means True;In this piece of code,when you dose not set the name,the name is False,and the cycle will begin,after you set name value, not name= False, and jump out the cycle

yaziLiang
  • 3
  • 4