Я вроде как новый для Python, и мне было интересно, как это исправить. Я пытаюсь сделать конвертер валют для школьного проекта для своего вычислительного класса, однако я получаю сообщение об ошибке.Получение ошибки типа с Python
Вот код:
## Currency conversion calculator Mk.2 ##
# USD, JPY, EUR
GBP = ["1.66","169.14","1.21"]
# GBP, JPY, EUR
USD = ["0.60","102.20","0.73"]
# GBP, USD, EUR
JPY = ["0.0059","0.0098","0.0072"]
# GBP, USD, JPY
EUR = ["0.82","1.36","139.70"]
# Inputs and outputs
user_input = -1
output = -1
while True:
print("")
print("----------------------------------------------------")
print("Example: 14 GBP to USD")
print("")
user_input = input("How much would you like to convert? ")
user_input = user_input.split()
if user_input[1] == "GBP":
if user_input[3] == "USD":
output = user_input[3] * USD[0]
print(output)
elif user_input[3] == "JPY":
print("Filler text")
elif user_input[3] == "EUR":
print("Filler text")
elif user_input[1] == "USD":
if user_input[3] == "GBP":
print("Filler text")
elif user_input[3] == "JPY":
print("Filler text")
elif user_input[3] == "EUR":
print("Filler text")
elif user_input[1] == "JPY":
if user_input[3] == "GBP":
print("Filler text")
elif user_input[3] == "USD":
print("Filler text")
elif user_input[3] == "EUR":
print("Filler text")
elif user_input[1] == "EUR":
if user_input[3] == "GBP":
print("Filler text")
elif user_input[3] == "USD":
print("Filler text")
elif user_input[3] == "JPY":
print("Filler text")
else:
print("Please input it as something like '15 GBP to USD' remembering capitals!")
Это ошибка я получил:
Traceback (most recent call last):
File "C:\Users\Kieran\Desktop\converter.py", line 27, in <module>
output = user_input[3] * USD[0]
TypeError: can't multiply sequence by non-int of type 'str'
Я на Python 3.3.3, кстати.
Большое спасибо!
Каковы ваши ожидаемые входы и выходы? – thegrinner
Почему вы используете строки для числовых значений? Используйте поплавок или десятичный тип. – geoffspear
Почему вы вызываете 'split' на входе? Чего вы ожидаете от пользователей? – IanAuld