【问题标题】:How to insert strings and variables into print statements?如何在打印语句中插入字符串和变量?
【发布时间】:2022-06-21 23:19:21
【问题描述】:

我正在尝试编写一些程序来显示我之前在打印语句中编写的变量,但每当我运行代码时它不会显示变量,它只是说“无”。

我的代码:

sidewalkclosed = True
raining = True
xPos = 400
yPos = 400
print("Your robot is located at",print(yPos),"on the y axis and",print(xPos),"on the x 
axis.")

【问题讨论】:

  • print(f"Your robot is located at {yPos} on the y axis and {xPos} on the x axis.")

标签: python


【解决方案1】:

试试这个。


sidewalkclosed = True
raining = True
xPos = 400
yPos = 400
print("Your robot is located at",yPos,"on the y axis and",xPos,"on the x 
axis.")
#### or ####
print(f"Your robot is located at {yPos} on the y axis and {xPos} on the x 
axis.")

【讨论】:

    【解决方案2】:

    你出于某种原因将 print() 放入 print() 中,只需将其更改为

    print("Your robot is located at",yPos,"on the y axis and",xPos,"on the x axis.")
    

    【讨论】:

      猜你喜欢
      • 2017-05-24
      • 1970-01-01
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 2021-03-09
      • 2021-01-01
      相关资源
      最近更新 更多