为什么我输入了函数报错了
def watchMovie(name="小甲鱼",cigaertte=True,beer=True,girlfirend=True):sentence = name+"带着"
if cigarette:
sentence = sentence+"香烟"
if beer:
sentence = sentence+"啤酒"
if girlfriend:
if cigarette or beer:
sentence=sentence+"和女朋友"
else:
sentence = sentence+"女朋友"
sentence = sentence+"去看电影"
return sentence
>>>
>>> watchMovie()
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
watchMovie()
File "<pyshell#15>", line 3, in watchMovie
if cigarette:
NameError: name 'cigarette' is not defined
cigaertte=True改成cigarette==True def watchMovie(name="小甲鱼",cigarette=True,beer=True,girlfirend=True):
sentence = name+"带着"
if cigarette:
sentence = sentence+"香烟"
if beer:
sentence = sentence+"啤酒"
if girlfriend:
if cigarette or beer:
sentence=sentence+"和女朋友"
else:
sentence = sentence+"女朋友"
sentence = sentence+"去看电影"
return sentence
页:
[1]