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

Why are my input values being rounded down?

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

>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

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