我是一個初學python程序員。請提供援助。無效的文字int()與基本錯誤,每次我輸入任何顏色
lightcolor=int(input("Enter Red,Green,Yellow,White,Purple,Blue,Orange,Brown,or Black->"))
if lightcolor=="Red":
print("Red Light-Please stop!!")
elif lightcolor=="Green":
print("Green Light-Please continue")
elif lightcolor=="Yellow":
print("Yellow Light-speed up")
elif lightcolor=="White":
print("White Light-its too bright")
elif lightcolor=="Purple":
print("Purple Light-pretty")
elif lightcolor=="Blue":
print("Blue Light-thats unusual")
elif lightcolor=="Orange":
print("Orange Light-bright as the sun")
elif lightcolor=="Brown":
print("Brown Light-like dirt")
elif lightcolor=="Black":
print("Black Light-very dark")
else:
print("Sorry no such color"),lightcolor
爲什麼我每次輸入任何顏色時都會遇到基本錯誤的int()無效文字?我正在使用Python 3.坦克的幫助我修復了整數,它工作。
要調用' int()'輸入()'值,而'int(「紅色」)'無效。 – Blckknght
因爲你想轉換爲一個整數,所以不能分析的字符串就像這樣=>「」Red「」或「Green」不是整數! –
通常,當您收到錯誤消息並在StackOverflow上詢問有關它的問題時,實際在您的問題中包含回溯會很有幫助。在這種情況下,這實際上並不是必要的 - @Blckknght是100%正確的。什麼是int在那裏呢?無處不在... – mgilson