Why are my input values being rounded down?

Question:

I am trying to make a decimal input valid however each time the decimal input gets rounded down. For example: When I input 1.5 the program will round down to 1 or if I input 5.5 it rounds down to 5. How can I make it so when I enter an input with a decimal place it calculates that exact input?

weight = int(float(input('What is the weight of your package?: ')))
#Shipping Costs
flat_rate = float(20.00)
if weight <= 2:
  price_per_pound = float(1.50)
  price = float(weight * price_per_pound + flat_rate)
  print(price)
if weight > 2 and weight <= 6:
  price_per_pound = float(3.00)
  price = float(weight * price_per_pound + flat_rate)
  print(price)
else:
print('invalid entry')
Asked By: Joseph

||

Answers:

Why are you storing a float in an int?
Change:

weight = int(float(input('What is the weight of your package?: ')))

to

weight = float(input('What is the weight of your package?: '))
Answered By: SpeedyTheSnail
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.