![](/img/trans.png)
[英]TypeError: can't multiply sequence by non-int of type 'str'
[英]What am I doing wrong? "TypeError: can't multiply sequence by non-int of type 'str'"
我是任何與編碼相關的新手,並且正在編碼課程中進行練習。 但我無法聯系那里的任何人,所以我在這里這樣做。 我正在使用 anaconda 的 Jupyter 6.0.1。
kingName = input("Hey king! Please type in your name at the prompt")
numJewels = input("Hey"+kingName+",how many jewels are there?")
costofEachJewel = input("Yo"+kingName+",how much does each jewels cost?")
totalPrizeSize = costofEachJewel*numJewels
TypeError Traceback (most recent call last)
<ipython-input-5-2badf11c0f15> in <module>
----> 1 totalPrizeSize =costofEachJewel*numJewels
TypeError: can't multiply sequence by non-int of type 'str'
您必須將它們轉換為 int,因為輸入始終是字符串,並且您必須告訴程序輸入應該是整數(如果您想允許浮點數,則必須是浮點數)。
kingName = input("Hey king! Please type in your name at the prompt")
numJewels = int(input("Hey "+kingName+",how many jewels are there?"))
costofEachJewel = int(input("Yo"+kingName+",how much does each jewels cost?"))
totalPrizeSize = costofEachJewel*numJewels
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.