This is the source site 我无法理解这段代码, “While not name:”指的是什么?如本文所述,它怎么可能与“not name!=”相同还有“客人”=“0”与“if numOfGuests:”相同: 你的帮助会很感激的
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')
在python中,null值表示False,非null值表示True;在这段代码中,当您没有设置名称时,
name
为False,在您设置name
值后,not name
=False,循环将开始,并跳出循环相关问题 更多 >
编程相关推荐