name 'cap_name' is not defined

来源:互联网 发布:淘宝开店卖虚拟物品 编辑:程序博客网 时间:2024/06/14 20:59

书上代码块

"""Spyder EditorThis is a temporary script file."""#hello.pydef say_hello_to(name):    cap_name=name.capitalize()print('hello'+cap_name+',how are you ?')

两个问题

1. print()函数应该在函数块内
2. 调用say_hello_to(name)函数,输入name时,应该加上引号‘name’或者”name”

正确代码

"""Spyder EditorThis is a temporary script file."""#hello.pydef say_hello_to(name):    cap_name=name.capitalize()    print('hello'+' '+cap_name+',how are you ?')

调用时

say_hello_to('liming')say_hello_to("liming")

结果

hello Liming,how are you ?hello Liming,how are you ?
原创粉丝点击