在python中如何将字符串乘以变量整数

2024-04-19 19:31:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法将字符串乘以一个整数变量。整数是变量形式,因为它是用户输入的输入。但是我不能让它们相乘,这样我就可以打印它们了。程序遵从并运行,但当遇到将它们相乘在一起的代码时,会遇到语法错误。在

gapVal=(" ")

gapSp=int(input("Please enter a the amount of spaces between the stars"))
gapSp2=(gapSp)-2
gapSp3=(gapSp2)-2

print("*", gapSp, "*", gapSp2, "*", gapSp3, "*")

Tags: the字符串代码用户程序input整数形式
1条回答
网友
1楼 · 发布于 2024-04-19 19:31:32

但是我知道你在做什么,你想要这样的代码吗?在

gapVal = " "

gapSp=int(input("Please enter a the amount of spaces between the stars"))
gapSp2 = gapSp - 2
gapSp3 = gapSp2 - 2

print("*", gapSp * gapVal,
      "*", gapSp2 * gapVal,
      "*", gapSp3 * gapVal, "*")

相关问题 更多 >