0

I am starting python again and i am stuck with how to get the users input in the form of an integer and float value then adding the entire amount given by the user of all the change into a full number or amount with the float value on the end. If you could help it would be appreciated sorry if this is very obvious.

# Change Calculator. To calculate change based on the amount of coins in hand 
print("Hello, welcome to the change calculator")
print("Here we will ask you to tell us the amount of each individual coins you have")

fivepence = float(0.05)
tenpence = float(0.10)
twentypence = float(0.20)
fiftypence = float(0.50)
onepound = int(1)
twopound = int(2)
#Get the user to input everything 

fivepencetotal = float(input(("How many 5 Pence coins do you have? : ")))

tenpencetotal = float(input(("How many 10 Pence coins do you have? : ")))

twentypencetotal = float(input(("How many 20 Pence coins do you have? : ")))

fiftypencetotal = float(input(("How many 50 pence coins do you have? : ")))

onepoundtotal = int(input(("How many 1 Pound coins do you have? : ")))

twopoundtotal = int(input(("How many 2 pound coins do you have? : ")))

#Here you add everything 
print("Just calculating how much money you have based on the data you have inputed")

print(fivepencetotal + tenpencetotal + twentypencetotal + fiftypencetotal + onepoundtotal + twopoundtotal)

  • Does this answer your question? [How do you read from stdin?](https://stackoverflow.com/questions/1450393/how-do-you-read-from-stdin) – Semo Jun 22 '20 at 12:17

1 Answers1

0

You don't need to write fivepence = float(0.05). You can instead write it as just fivepence = 0.05. The float() function converts to a float, but isn't necessary to define a float. When you are getting the fivepencetotal you can write this:

fivepencetotal = float(input(("How many 5 Pence coins do you have? : "))) * fivepence

Repeat the steps for the other coin values and it should work.

Max
  • 126
  • 5