How to make Python multiply user input with a given fractional number?

Question:

I’m making a currency exchange program, but NOK (the user input in Norwegian kroner) won’t multiply with 0,10 and 0,11.

NOK = input("Enter the amount you wish to convert: ")
print (f"Your choosen amount is {NOK} NOK")
print("What do you wish to convert it to?")
Question = input("EUR or USD")
if Question == "EUR":
    print({NOK} * 0,10)
elif Question == "USD":
    print({NOK} * 0,11)
else:
    print("Please anwser 'EUR' or 'USD'")
Asked By: Noell

||

Answers:

Good to see you’re taking up coding.

There are a few issues with the code you provided.

  1. You need to indent code inside if, elif, else blocks. This means insert a tab or 4 spaces before every line inside the block.
  2. Python uses the period for the decimal seperator, unlike the comma used in European countries.
  3. Do not use curly brackets when referencing variables.
  4. Your NOK input is taken as a string (text), whereas it needs to be an integer (number) to multiply it. This is done with int() around your input()

Additionally, you should not name your variables starting with capital letters as these are traditionally reserved for classes.

Try this instead:

nok = int(input("Enter the amount you wish to convert: "))
print(f"Your choosen amount is {nok} NOK")
print("What do you wish to convert it to?")

question = input("EUR or USD")
if question == "EUR":
    print(nok * 0.10)
elif question == "USD":
    print(nok * 0.11)
else:
    print("Please anwser 'EUR' or 'USD'")
Answered By: ninjadev64

You don’t need to write NOK between {} and you have to transform the answer in integer to multiple it.

NOK = int(input("Enter the amount you wish to convert: ")) 
print ("You choosen amount is {NOK} NOK")
print("What do you wish to convert it to?")
Question = input("EUR or USD")
if Question == "EUR":
   print(NOK * 0,10)
elif Question == "USD":
    print(NOK * 0,11)
else:
    print("Please anwser 'EUR' or 'USD'")
Answered By: Tarezze
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.