【发布时间】:2015-04-12 17:28:04
【问题描述】:
这只是我的程序的一小部分,所以我只是一块一块地创建它。所以我现在要做的就是让我的程序在输入小于或等于 10 时向 ast1 添加一个“*”,但我不断收到错误“无法将'int'对象隐式转换为 str”我不完全确定为什么。有人可以在这里给我一根骨头并帮助我。
ast1 = "*"
count = 0
while (True):
n = int(input("Enter a number between 0 - 100:"))
if n<=10:
ast1 = ast1 + 1 #This is where the error is occuring
print(ast1)
编辑代码:当用户输入“完成”时,如何让该程序终止/中断?
ast1 = ""
ast2 = ""
ast3 = ""
ast4 = ""
while (True):
n = int(input("Enter a number between 0 - 100:"))
if n>=0 and n<=25:
ast1 = ast1 + "*"
elif n>25 and n<=50:
ast2 = ast2 + "*"
elif n>50 and n<=75:
ast3 = ast3 + "*"
elif n>75 and n<=100:
ast4 = ast4 + "*"
else:break
print(ast1)
print(ast2)
print(ast3)
print(ast4)
【问题讨论】:
标签: python string int concatenation