-
-
Save TheMuellenator/fc9f7ffb3075da52a5953f859e01aee0 to your computer and use it in GitHub Desktop.
# TODO 1: Add two parameters (length_ft and width_ft) | |
def calc_square_meters_from_feet(length_ft, width_ft): | |
# TODO 2: Modify the code below: | |
metric_length = length_ft * 0.3048 | |
metric_width = width_ft * 0.3048 | |
metric_area = metric_length * metric_width | |
# Leave the line below as it is | |
return metric_area |
metric_area = (length * 0.3048 ) * (width * 0.3048)
In the above statement if I remove the brackets & check solution then it says Öops your solution is incorrect"
348.38640000000004 != 348.3864I think you need to correct your code which checks the answer or you need to reason out on why this happens & how the brackets are causing this difference in the resolution of digits after decimal point?
Hi,
just want to share sth searched on the internet about the issue with the float calculation.
"It’s a problem caused when the internal representation of floating-point numbers, which uses a fixed number of binary digits to represent a decimal number. It is difficult to represent some decimal number in binary, so in many cases, it leads to small roundoff errors."
Hi everyone, didn't get this task really. Even if i copy and paste what you suggested i got this error, can anyone help, why i'm getting it?
- You are passing the arguments as string. When you write the numbers within quotes, they are treated as strings. Remove the quotes and just type 5,10
calc_square_meters_from_feet(5,10)
-
In the Function definition piece, you need to add a return statement. Only then the function will return the answer.
return metric_area
the complete code would look like the below:
def calc_square_meters_from_feet(length_ft, width_ft):
metric_length=length_ft0.3
metric_width=width_ft0.3
metric_area=metric_length*metric_width
return metric_area
calc_square_meters_from_feet(5,10)
Output: 4.5
def calc_square_meters_from_feet(length_ft, width_ft):
print(length_ft * width_ft * 0.3048)
My version of this code
TODO 1: Add two parameters (length_ft and width_ft)
def calc_square_meters_from_feet():
legnth_ft = float(input("what is legnth_fit?")) * float(0.3048)
widht_ft = float(input("what is width_ft?")) * float(0.3048)
square_feet = float(legnth_ft) * float(widht_ft)
metric_area = square_feet
# Leave the line below as it is
return metric_area
calc_square_meters_from_feet()
ez and simple
def calc_square_meters_from_feet(lft,wft):
# TODO 2: Modify the code below:'
lft= lft * 0.3048
wft= wft * 0.3048
metric_area = lft * wft
# Leave the line below as it is
return metric_area
This is my solution:
def calc_square_meters_from_feet(length_ft, width_ft): return round(((length_ft * width_ft) * 0.3048) * 0.3048, 4)
I added a round() and now it is accepted
def calc_square_meters_from_feet(length_ft, width_ft):
# TODO 2: Modify the code below:
metric_area = 0
metric_area= length_ft*0.3048*width_ft*0.3048
metric_area= round(metric_area,4)
# = the line below as it is
return metric_area
@catalinazz that's good
metric_area = (length * 0.3048 ) * (width * 0.3048)
In the above statement if I remove the brackets & check solution then it says Öops your solution is incorrect"
348.38640000000004 != 348.3864
I think you need to correct your code which checks the answer or you need to reason out on why this happens & how the brackets are causing this difference in the resolution of digits after decimal point?