[英]can't multiply sequence by non-int of type 'float' Python
so I am currently trying to do a currency converter. 所以我目前正在尝试做一个货币转换器。 Here is the code: 这是代码:
Choice = 0
Amount = 0
Converted = 0
Staff = False
print("Welcome to currency converter - Here are your options: ")
print("1. Dollars to sterling")
print("2. Euros to sterling")
print("3. Sterling to dollars")
print("4. Sterling to euros")
Choice=input("Please type the number of your choice")
Amount=input("Enter the amount you would like to convert")
if Choice == "1":
Amount = Amount * 0.80
elif Choice == "2":
Amount = Amount * 0.89
print(Amount)
This is the error I get: 这是我得到的错误:
TypeError: can't multiply sequence by non-int of type 'float'
I have tried these solutions: 我已经尝试过以下解决方案:
Amount=input(float("Enter the amount you would like to convert"))
if Choice == "1":
Amount = Amount * float(0.80)
if Choice == "1":
Amount = float(Amount * 0.80)
None of these solutions work and I keep getting the same error - I would appreciate it when providing a fix you explain why this error occurs in a basic way - Thanks! 这些解决方案均无法正常工作,而且我会不断遇到相同的错误-在提供修复程序时,您会以一种基本的方式解释为什么会发生此错误,不胜感激-谢谢!
Amount
is a str
, not a float
. Amount
是一个str
,而不是float
。 You need to make an explicit conversion first. 您需要先进行显式转换。
Amount = float(input("..."))
or 要么
Amount = float(Amount) * 0.80
You are applying float(...)
to just about everything except what it needs to be applied too. 您正在将float(...)
应用于几乎所有事物,除了它也需要应用之外。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.