#Designing a program which generates housing occupancy report
18 messages · Page 1 of 1 (latest)
get_data doesn't return anything
but you're assigning the return value of get_value to variables
also, please copy and paste your code rather than screenshotting your editor
my bad
`# -- coding: utf-8 --
"""
Created on Thu Oct 6 09:38:40 2022
@author: minut
"""
def get_data():
h0 = int(input("Provide the number of houses with 0 occupancy: "))
h1 = int(input("Provide the number of houses with 1 occupancy: "))
h2 = int(input("Provide the number of houses with 2 occupancy: "))
h3 = int(input("Provide the number of houses with 3 occupancy: "))
h4 = int(input("Provide the number of houses with 4 occupancy: "))
h5 = int(input("Provide the number of houses with 5 occupancy: "))
h6 = int(input("Provide the number of houses with 6 occupancy: "))
h7 = int(input("Provide the number of houses with 6+ occupancy: "))
def cal_percentage(h0,h1,h2,h3,h4,h5,h6,h7):
total = h0+h1+h2+h3+h4+h5+h6+h7
p0 = h0100/total
p1 = h1100/total
p2 = h2100/total
p3 = h3100/total
p4 = h4100/total
p5 = h5100/total
p6 = h6100/total
p7 = h7100/total
def display_result(h0,h1,h2,h3,h4,h5,h6,h7,p0,p1,p2,p3,p4,p5,p6,p7):
#student writes code
if name="main":
h0,h1,h2,h3,h4,h5,h6,h7=get_data()
p0,p1,p2,p3,p4,p5,p6,p7 = cal_percentage(h0,h1,h2,h3,h4,h5,h6,h7)
display_result(h0,h1,h2,h3,h4,h5,h6,h7,p0,p1,p2,p3,p4,p5,p6,p7)`
I think you should review how functions and return values work
because the variable h0 within the get_data() function is unrelated to the h0 variable at the end of your program
i'm really stuck the teacher told me its fine so far and need to touch up on the end
i disagree with your teacher, this code looks wrong to me
`# -- coding: utf-8 --
"""
Created on Thu Oct 6 09:38:40 2022
@author: minut
"""
def get_data():
#student writes code
def cal_percentage(h0,h1,h2,h3,h4,h5,h6,h7):
#student writes code
def display_result(h0,h1,h2,h3,h4,h5,h6,h7,p0,p1,p2,p3,p4,p5,p6,p7):
#student writes code
if name="main":
h0,h1,h2,h3,h4,h5,h6,h7=get_data()
p0,p1,p2,p3,p4,p5,p6,p7 = cal_percentage(h0,h1,h2,h3,h4,h5,h6,h7)
display_result(h0,h1,h2,h3,h4,h5,h6,h7,p0,p1,p2,p3,p4,p5,p6,p7)`
this is what was given
i'm not going to try to convince you
but i think the code you filled out is incorrect, for the reasons previously stated
i know but they said it has to be written in that type of format
i'm saying the code you filled out is incorrect
oh
`# -- coding: utf-8 --
"""
Created on Thu Oct 6 09:38:40 2022
@author: minut
"""
def get_data():
h0 = int(input("Provide the number of houses with 0 occupancy: "))
h1 = int(input("Provide the number of houses with 1 occupancy: "))
h2 = int(input("Provide the number of houses with 2 occupancy: "))
h3 = int(input("Provide the number of houses with 3 occupancy: "))
h4 = int(input("Provide the number of houses with 4 occupancy: "))
h5 = int(input("Provide the number of houses with 5 occupancy: "))
h6 = int(input("Provide the number of houses with 6 occupancy: "))
h7 = int(input("Provide the number of houses with 6+ occupancy: "))
return h0, h1, h2, h3, h4, h5, h6, h7
def cal_percentage(h0,h1,h2,h3,h4,h5,h6,h7):
total = h0+h1+h2+h3+h4+h5+h6+h7
p0 = h0100/total
p1 = h1100/total
p2 = h2100/total
p3 = h3100/total
p4 = h4100/total
p5 = h5100/total
p6 = h6100/total
p7 = h7100/total
return p0, p1, p2, p3, p4, p5, p6, p7
def display_result(h0,h1,h2,h3,h4,h5,h6,h7,p0,p1,p2,p3,p4,p5,p6,p7):
#student writes code
if name="main":
h0,h1,h2,h3,h4,h5,h6,h7=get_data()
p0,p1,p2,p3,p4,p5,p6,p7 = cal_percentage(h0,h1,h2,h3,h4,h5,h6,h7)
display_result(h0,h1,h2,h3,h4,h5,h6,h7,p0,p1,p2,p3,p4,p5,p6,p7)`