我正在尝试调用我的函数overwatch
。它应打印出bastion
和lucio
。
我的代码对我来说很合适。但是我遇到了一些错误,我不知道为什么我会收到错误。
def overwatch(hero1, hero2):
print("hello " + hero1 "and " hero2)
overwatch(bastion, lucio)
答案 0 :(得分:1)
您在字符串文字周围错过了两个+
符号和引号。
def overwatch(hero1, hero2):
print("hello " + hero1 + " and " + hero2)
overwatch('bastion', 'lucio')
答案 1 :(得分:1)
首先,您希望bastion和lucio作为字符串变量,因此您需要使用overwatch('bastion','lucio')
。此外,在print语句中,您需要添加一个加号:
print("hello " + hero1 "and "+ hero2)
答案 2 :(得分:1)
错误,你看到的是:
print("hello " + hero1 "and " hero2)
^
SyntaxError: invalid syntax
解决方案很简单:
你应该编辑你的代码:
1)print("hello " + hero1 + "and " + hero2)
2)overwatch("bastion", "lucio")