# EX5_fraction to inches?

Hello, in EX5 we are giving hte height in inches, is there a way to get it expressed in Feet + inches (not decimal)?
I tried a couple of different ways but seem to be stuck on this output: Appreciate any help.
Cheers. — B.

What are you trying to do with `set`?

Try this in the REPL:

``````>>> inches = 0.75
>>> inches * 100
75.0
>>> int(inches * 100)
75
``````

Yes, I’m curious with @florian about what’s the use of `set()` here. Normally that’s for doing a mathematical set() object, so I think you may be thinking it’s…setting a variable?

Also, you can paste your code like this:

``````[code]
[/code]
``````

Way easier.

@ Florian & Zedshaw
Okay, for the set I was thinking (noob w/Python) it would take the decimal and if matched would return the “set” number, so that I could have it list it as a whole number in inches.
So instead of 5.75 show as 5 Ft 9 in. etc.

@ Florian
For this,

inches = 0.75
inches * 100
75.0

int(inches * 100)
75

DATA: 69 inches or 5.75 Feet = 5 Ft 9 Inches

Not sure that is going to give me the 0.75 (9 inches) as a proper output as (9) inches, I am trying to get the output to show 5 ft 9 in instead of 5.75 Feet. Thanks! — B.

You mean like?

``````if newinches == 0.75:
print “9”``````

I think you’ll come onto conditionals soon enough which might help, but really the way to manage that conversion would be via a dedicated function call to return the answer in the format you wanted. Otherwise you need to have a massive list or dictionary of potential values.

Great exploration of the language though given the early exercise.

1 Like

Welcome to the US measurements! Alright, so you get a decimal number for a fraction of a foot like 0.75. You want to translate that to inches, and there are 12 inches in a foot:

``````12 * 0.75
``````

That should do it.

1 Like What a fun system! Over here it’s all multiples of ten.

1 Like

Thank you, will play around with that. Yes, I was creating a dictionary/list for all 11 inches thinking to go that way but the output I kept getting was weird. Cheers. — B.

@florian- Same here unless it’s beer or bread bizarrely.

Yes, just the US and 4 other countries in the whole world…
US should go to the Metric system! Thank you, I will see how that works out and let you know.
Cheers. — B

Okay, after a bit of trial and error I came up with this:

``````name = 'Benjamin' # First set all variables

age = 66  # true and retired

height = 69 # inches

weight = 165 # lbs - although it varies btw 160-165

eyes = 'blue-green'

teeth = 'white'

hair = 'gray'

total = age + height + weight

kg = round (weight * 0.453592, 1)  # (,1) rounds it to ONE digits

M = round (height * 0.0254, 2)     # (,2) rounds to TWO digits - Metric

# get whole number for feet, omit fraction - use trunc

import math # calling a math function for next line

newheight = math.trunc(height/12) # truncates to whole number - ingnores all fractions

newinches = (height/12 - newheight) # gets the remaining inches in decimals

dinch = round (newinches * 12) # take the decimal output, multiply by 12 to get whole inches

cinch = math.trunc(dinch) # now make Cinch a whole number, no decimal

# I still wonder if above 5 lines can be done in less lines by combining statements?

print("") # line spacer

print(f"Let's talk about {name}.")

print(f"He's {height} inches tall, or {newheight} Ft {cinch} in.")

print(f"He weighs {weight} pounds.")

print("Actually that's not too heavy.")

print(f"He's got {eyes} eyes and {hair} hair.")

print(f"His teeth are usually {teeth} depending on the amount of coffee consumed...")

print("") # line spacer

# This next line is a bit tricky, try to get it exactly right

print(f"If I add the age {age}, height {height}, and weight {weight} it totals {total}.")

print("") # line spacer

print(f"The weight converts to {kg} kilograms")

print(f"The hight converts to {M} meters")

print("") # line spacer``````

I tried it with several different heights and seems to do the job well now, so ex5 done for now. Here is the output: Success! Good job creating a nice puzzle to solve.

1 Like