Home > Blockchain >  Why are my input values being rounded down?
Why are my input values being rounded down?

Time:08-13

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

CodePudding user response:

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?: '))
  • Related