199k views
3 votes
Read the following code used to calculate the percentage of calories from fat in an item:

calories = input("How many calories are in the item? ")

caloriesFat = input("How many calories are from fat? ")

percentFat = caloriesFat / calories


There is an error in the code. What type of function needs to be used?


float() [I think it is this one. Is it right?]

int()

print() [NOT this one!]

str()

2 Answers

6 votes

Answer:

The answer is int ()

Step-by-step explanation:

Process of elimination. Only int and float are used for calculation (division obvs falls under that). Disregard the other two options. Float is for numerical values with a decimal. Calories are never shown with decimal points. So, it's int()

User Jwogrady
by
8.5k points
4 votes

Step-by-step explanation:

Problem is to cast your input values either in int() or float() this this up to you in which format you want your output,

Example2:

calories = int(input("How many calories are in the item? "))


caloriesFat = int(input("How many calories are from fat? "))


percentFat = int(caloriesFat / calories)

Now output on the screen:

print(percentFat)


Example2:

calories = float(input("How many calories are in the item? "))


caloriesFat = float(input("How many calories are from fat? "))


percentFat = float(caloriesFat / calories)

Now output on the screen:

print(percentFat)

I hope you got the idea Thanks

User Maarten Boekhold
by
8.4k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.