這只是我的程序的一小部分,所以我只是一件件地創建它。所以我現在要做的就是讓我的程序向ast1添加一個「*」,如果輸入小於或等於10,但我總是收到錯誤「無法將int'對象隱式轉換爲str」我不完全確定爲什麼。有人可以在這裏把我的骨頭扔給我,幫助我。爲什麼我得到錯誤「無法將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)
不,這不是我想要的,儘管您確實給了我更多的知識。我爲我的作業做的是創建一個程序,它將輸入0-100之間的任意數字,直到所輸入的字符串是「done」,然後從那裏我將打印每個數字的星號數量[ 0,25](25,50](50,75)(75,100),但我喜歡在小部分中完成作業。 – HawkeyeNate 2015-02-12 05:13:01