新手for函数求助
for magician in magicians:print(f"{magician.title()}, that was a great trick!")
print(f"I can't wait to see your next trick, {magician.title()}.\n")
应该最后输出结果是这样
Alice, that was a great trick!
David, that was a great trick!
Carolina, that was a great trick!
I can't wait to see your next trick, Carolina.
跟着书上来的,最后出来就是语法错误,这里到底错在哪呢了,magicians是一个带有多个字符串的列表,求大佬解答! 这个可以执行没问题啊
magicians = ['A','D','C','car']
for magician in magicians:
print(f"{magician.title()}, that was a great trick!")
print(f"I can't wait to see your next trick, {magician.title()}.\n")
============================= RESTART: E:\py\123.py ============================
A, that was a great trick!
D, that was a great trick!
C, that was a great trick!
Car, that was a great trick!
I can't wait to see your next trick, Car.
>>> 代码不全,谁知道咋回事 nikezhi 发表于 2022-6-22 16:47
这个可以执行没问题啊
magicians = ['A','D','C','car']
https://s2.loli.net/2022/06/22/RPHFf3Niyb2sYQe.jpg
麻烦再看看这个图片我也是很疑惑 wp231957 发表于 2022-6-22 16:53
代码不全,谁知道咋回事
前面还有个magicians = ['alice','david','carolina']{:10_250:} nikezhi 发表于 2022-6-22 16:47
这个可以执行没问题啊
magicians = ['A','D','C','car']
我确实就返回的是语法错误,会不会是因为用的是IDLE呢 发不了图片太难啦{:10_266:} 无所事事的猪 发表于 2022-6-22 17:49
我确实就返回的是语法错误,会不会是因为用的是IDLE呢 发不了图片太难啦
你是在三个大于号下写的代码???
如果这样的话是不行的(不建议在>>>下编写多行代码) 无所事事的猪 发表于 2022-6-22 17:49
我确实就返回的是语法错误,会不会是因为用的是IDLE呢 发不了图片太难啦
IDLE里面只能一句一句代码写啊,那肯定会报错啊,创建一个文件来写 nikezhi 发表于 2022-6-22 21:10
IDLE里面只能一句一句代码写啊,那肯定会报错啊,创建一个文件来写
试了下new file就可以啦但是这里还有个疑问是必须保存后才能运行吗 我点run model就让我保存保存后才能运行 这个运行结果还是弹出的另外一个shell上正常都是这样吗{:10_291:} 无所事事的猪 发表于 2022-6-23 10:23
试了下new file就可以啦但是这里还有个疑问是必须保存后才能运行吗 我点run model就让我保存保存 ...
是啊,必须保存才能运行 nikezhi 发表于 2022-6-23 13:19
是啊,必须保存才能运行
好的 谢谢你!你真好{:10_281:}
页:
[1]