Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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'")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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'")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading