Can't Multiply Sequence By Non-int Of Type 'str' Dont Understand
yen = 0.0067 bsp = 1.35 usd = 0.65 ero = 0.85 if choice == '2': Current_Currency = input('What currency do you want to exchange: Japenese Yen if so please type yen // British
Solution 1:
It looks like you are confusing variable names with variables. Because the currency type you get from the user is a string, it can't be used to reference variables unless you call eval on it.
new_amount = eval(future_currency) * amount
The downside of this is that using eval
gives the user a possible way to affect your code. Instead, you can use a dictionary. Dictionaries map strings to values, and so you can take your variable declarations:
yen = 0.0067bsp = 1.35usd = 0.65ero = 0.85
And turn them into a dictionary:
currencies = {'yen': 0.0067, 'bsp': 1.35, 'usd': 0.65, 'ero': 0.85}
Using this, you can find the value you are looking for in the dictionary. Don't forget to handle incorrect user input properly!
currencies = {'yen': 0.0067, 'bsp': 1.35, 'usd': 0.65, 'ero': 0.85}
current_currency = raw_input()
future_currency = raw_input()
amount = int(raw_input())
// Check for errors in input here
new_amount = amount * currencies[future_currency] / currencies[current_currency]
Solution 2:
The line
Current_Currency = input("What currency do you want to exchange: Japenese Yen if so please type yen // British Sterling Pound please type bsp // US Dollers please Type usd // Euro please type ero.")
will throw an error if an unknown variable is entered, and Current_Currency
will be set to the value of the variable name provided by the user, so the line
ifCurrent_Currency== "yen":
isn't really needed.
yen = 0.0067bsp = 1.35usd = 0.65ero = 0.85Current_Currency = input("What currency do you want to exchange: Japenese Yen if so please type yen // British Sterling Pound please type bsp // US Dollers please Type usd // Euro please type ero.")
amount = input("Type amount you wish to exchange")
Future_Currency = input("What currency do you want to exchange into: Japenese Yen if so please type yen // British Sterling Pound please type bsp // US Dollers please Type usd // Euro please type ero.")
New_Amount = Current_Currency / Future_Currency * amount
Post a Comment for "Can't Multiply Sequence By Non-int Of Type 'str' Dont Understand"