You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python故事生成编程练习:代码输出与预期不符问题排查

修正后的代码
name = input("Please type in a name: ")
year = input("Please type in a year: ")
print(f"{name} is a valiant knight, born in the year {year}.")
print(f"One morning Mary woke up to an awful racket: a dragon was approaching the village. Only {name} could save the village's residents.")
修改说明
  • 改用f-string格式化字符串,既简化代码,又将年份整合到第一句输出中,消除不必要的换行。
  • 调整年份后的标点格式,添加空格避免.One连在一起的问题,匹配预期输出的排版。
  • 将故事末尾固定的Mary替换为输入变量name,让拯救村庄的角色与用户输入的名字一致,符合预期逻辑。

内容的提问来源于stack exchange,提问作者EngWisp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 09:39:56