0

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!

Dan
  • 137
  • 2
  • 9
  • `float(input(.....))`. You tried everything except the correct solution – Charif DZ Sep 16 '19 at 19:33
  • Your first attempted solution is _almost_ right -- you want `float(input(...))`, not `input(float(...))`. – John Gordon Sep 16 '19 at 19:33
  • 1
    Possible duplicate of [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – Sayse Sep 16 '19 at 19:34

1 Answers1

2

Amount is a str, not a 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.

chepner
  • 497,756
  • 71
  • 530
  • 681