-2

I cannot input a decimal as it comes up with this error

I've tried putting "float" function in different places

def Change():
  Money = int(input("How Much Money Do You Want To Change For Cash? - "))
  CoinType = int(input("What Type Of Coin Do You Want To Change Into? (1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01) - "))
  float(CoinType)
  if CoinType == 1:
    print("You Will Get", Money / CoinType,"Coins")
  if CoinType == 0.50:
    print("You Will Get", Money / CoinType,"Coins")

It should come up with "You will get", Money / CoinType, "Coins"

  • 1
    Try `float` in place of `int` – Rakmo May 14 '19 at 13:55
  • 1
    sidenote: do not store currency in floats. use the smallest denomination and ints. (so, 100 instead of 1, and 1 instead of 0.01). Convert at the end if really needed. Because [floats have their problems.](https://docs.python.org/3/tutorial/floatingpoint.html) – Paritosh Singh May 14 '19 at 13:58

3 Answers3

1

You are expecting int input whereas you instruct your user to pass a float value in the following line:

CoinType = int(input("What Type Of Coin Do You Want To Change Into? (1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01) - "))

Therefore, changing it to float should fix the problem:

CoinType = float(input("What Type Of Coin Do You Want To Change Into? (1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01) - "))
sophros
  • 11,665
  • 7
  • 38
  • 61
0

You should use float

CoinType = float(input("What Type Of Coin Do You Want To Change Into? (1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01) - "))
rdas
  • 18,048
  • 6
  • 31
  • 42
0

Use float in place of int. Integers (int) will not accommodate any decimal

Rakmo
  • 1,588
  • 2
  • 17
  • 34