#🔒 Need help with Python homework

142 messages · Page 1 of 1 (latest)

lost bloom
#

Forensics experts collect data from crime scenes and use mathematics to help solve some unanswered questions about the crime. One of the physical tools they use are calipers to measure the length and width of blood drops or hair follicles. To determine angles of impact they use the law of sine and even the law of tangents to calculate the height of the source.

Create a program that will allow investigators to type in their measurement findings and output answers to help in their investigation.

Create a project named Forensics with two major functions getHairType and getHeight. Be sure to use at least four instance field, medullaDiameter, entireHair, femurHeight, and gender. Create a getter and a setter for each instance field.

Hair Type

The program should have a function named getHairType that receives two parameters, medulla diameter and entire hair diameter. The function should calculate the ratio of the diameter of the medulla to the diameter of the entire hair. Use millimeters as the unit of measure. Animal hair exhibits ratio of .5 or higher. A ratio less than .5 is considered human hair. The program should return a 1 for human hair and a 0 for animal hair. (20 pts)

Human Height

The program should also have a function named getHeight. Scientists measure the human body using proportions. In a crime scene investigation, a person’s height can be estimated using the femur. A formula is used depending on the gender of the person.

Male: height = 69.089 + 2.238f (f stands for the femur length in cm)

Female: height = 61.412 + 2.317f (f stands for the femur length in cm)

The function receives the gender as an integer 0 for Male and 1 for Female and the length of a femur in centimeters. The function should return the height of the victim in centimeters.

queen merlinBOT
#

@lost bloom

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

spiral depot
lost bloom
#

The issue is I'm just lost and not sure where to go

#

i've just been typing and deleting for some time

spiral depot
#

Do you have any code to begin with?

lost bloom
#

I have a bit

spiral depot
#

!code

queen merlinBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

lost bloom
#
def main():
    starting_message()
    input('Please enter the medulla width in mm: ')
    input('Please enter the entire hair width in mm:')

def starting_message():
    print('Welcome Inspector,')
main()
clear shale
#

lol

lost bloom
#

sorry was trying to figure out how to send this

clear shale
#

give it to chatgpt

spiral depot
#

Don’t

#

It’ll give you garbage

clear shale
spiral depot
#

@lost bloom why don’t we start one step at a time

lost bloom
#

even if ai would solve it I'd like to learn it

spiral depot
#

How about we first try creating the hair function

#

@lost bloom why don’t you create a def statement with a function that has 2 inputs

lost bloom
#

alright i'll give it a try

spiral depot
#

Let me know if you get stuck anywhere

lost bloom
#
def get_hair():
    input("Enter medulla width in mm: ")
    input('Enter hair width in mm: ')
#

is this good?

spiral depot
#

So it requires the inputs to be part of the function def

#

Let me show you an example

#

!e
def Add(x,y):
return x+y

print(Add(4,5))

queen merlinBOT
#

@spiral depot :white_check_mark: Your 3.12 eval job has completed with return code 0.

9
spiral depot
#

@lost bloom do you see how Add has x and y in those brackets

#

That’s what you need for your function

#

You need input variables

lost bloom
#

would my input variables be the medulla width and hair width?

spiral depot
#

Yep

#

So you need to name x and y as that

lost bloom
#

as in put the medulla width and hair width in the place of x and y?

spiral depot
#

Yes

#

And you’d rename Add to what your function name is

#

If you were to use my one as an example

lost bloom
#
def get_hair(medulla width, hair width):
#

something like this?

spiral depot
#

Yep

#

And now you’d need to have your function do what the question asked

lost bloom
#

for that it's just putting an equation under the def_get hair function right?

#

as it's asking for the ratio of the two

spiral depot
#

Yep

#

And then check if it’s more or less than 0.5

#

And then return 1 or 0

#

Let me know what you have and we can work from there

lost bloom
#

I think I might have gotten it!

#
def get_hair():
    medulla_width = float(input('Enter the medulla width in mm: '))
    hair_width = float(input('Enter the hair width in mm: '))
    ratio = medulla_width / hair_width
    if ratio >= 0.5:
        print('The sample provided is from an animal')
    if ratio < 0.5:
            print('The sample provided is from a human')
#

this is what I have thus far

#

I used numbers from examples that the professor provided when testing it and all the results have given me the right answer

spiral depot
#

That’s great

lost bloom
#

Thank you!

#

Im currently attempting the other part of the homework

#

the get_hight function

lost bloom
#

I've got the second part down aswell

#

my only thing is I'd like to make the output more organized with some spaces in between

#

similiar to this

#

currently everything outputs squished together

spiral depot
#

If you put ‘\n’ at the end of your prints it adds a space

#

!e
print('This adds a space\n')
print('Even tho both codes are next to each other')

queen merlinBOT
#

@spiral depot :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | This adds a space
002 | 
003 | Even tho both codes are next to each other
lost bloom
#

Oh I see

#

Okay I've got all of the functions to work and give accurate results but theres one more thing I wanted to do

#

If you look at the screenshot I sent earlier it doesn't provide the results till the very end

#

whereas my current code provides the the first half of the output in the middle and the second half of the output at the end

#

How would I get the "The sample provided" and the "The height is estimated to be" to come all at the end

#
def main():
    starting_message()
    get_HairType()
    get_Height()


def starting_message():
    print('Welcome Inspector,\n')
    print('Hair Analysis:')
def get_HairType():
    medullaDiameter = float(input('Enter the medulla width in mm: '))
    entireHair = float(input('Enter the hair width in mm: '))
    ratio = medullaDiameter / entireHair
    if ratio >= 0.5:
        print('The sample provided is from an animal')
    if ratio < 0.5:
            print('The sample provided is from a human')
def get_Height():
    gender = float(input('Please enter the gender(0 for male or 1 for female): '))
    femurHeight = float(input('Please enter the femur length in cm: '))
    male_height = 69.089 + 2.238 * femurHeight
    female_height = 61.412 + 2.317 * femurHeight
    if gender == 0:
        print('The height is estimated to be', male_height)
    if gender == 1:
        print('The height is estimated to be', female_height)
    
main()

#

this is currently the code I have

#

I doubt it's necessary to the grade of my homework but I want to make it neater

placid gyro
#

fyi you probably should pick a naming convention and stick with it, e.g. femur_height instead of femurHeight

#

!pep 8

queen merlinBOT
placid gyro
#

PEP 8 suggests snake case anyways.

lost bloom
#

Ya I was using that orginally and noticed in the professor's instruction he has us use what I currently have so I just stuck with it

placid gyro
#

oh all right

#

the professor is always correct :P

#

good luck with your stuff

lost bloom
#

actually do you mind helping me with what I asked earlier

placid gyro
#

What?

lost bloom
#

Oh I see
Okay I've got all of the functions to work and give accurate results but theres one more thing I wanted to do
If you look at the screenshot I sent earlier it doesn't provide the results till the very end
whereas my current code provides the the first half of the output in the middle and the second half of the output at the end
Image
How would I get the "The sample provided" and the "The height is estimated to be" to come all at the end
def main():
starting_message()
get_HairType()
get_Height()

def starting_message():
print('Welcome Inspector,\n')
print('Hair Analysis:')
def get_HairType():
medullaDiameter = float(input('Enter the medulla width in mm: '))
entireHair = float(input('Enter the hair width in mm: '))
ratio = medullaDiameter / entireHair
if ratio >= 0.5:
print('The sample provided is from an animal')
if ratio < 0.5:
print('The sample provided is from a human')
def get_Height():
gender = float(input('Please enter the gender(0 for male or 1 for female): '))
femurHeight = float(input('Please enter the femur length in cm: '))
male_height = 69.089 + 2.238 * femurHeight
female_height = 61.412 + 2.317 * femurHeight
if gender == 0:
print('The height is estimated to be', male_height)
if gender == 1:
print('The height is estimated to be', female_height)

main()

#

sorry if looks strange

#

just copy and pasted what I had earlier

placid gyro
#

You want to group all your output at the end?

lost bloom
#

Yep

#

I know I'd probably have to move some code but I'm not sure how that would work

placid gyro
#

How do you think you would do that given that you've got everything spread out across different functions?

lost bloom
#

Ya thats what im stuck on😓

placid gyro
#

does your professor want you to use Python specifically?

lost bloom
#

ya it's an intro to programming class that uses only python

placid gyro
#

Also the instructions mention instance attributes with getters and setters. Does your professor want you to make this a class?

lost bloom
#

I'll be honest I'm not to sure

placid gyro
#

You should probably find out haha

lost bloom
#

what are getter and setters?

#

the only class resource we have is out textbook

#

he doesn't provide anything else so I'm kind of in the dark a lot

placid gyro
#

For example: ```py

label.py

class Label:
def init(self, text, font):
self._text = text
self._font = font

def get_text(self):
    return self._text

def set_text(self, value):
    self._text = value

def get_font(self):
    return self._font

def set_font(self, value):
    self._font = value
#

You can intuit what they do. They get and set "private" variables. Python doesn't have private variables like other languages do that's why we use the underscore as the first character.

#

In languages like Java or C++ it's a little different.

#

_text is an attribute of Label

lost bloom
#

I'm sorry but I'm still lost

#

i looked through this weeks chapter and can't find anything

#

its an online class and if I'm being honest the professor doesn't help a whole lot

placid gyro
#

You can't find anything about classes you mean?

lost bloom
#

ya

placid gyro
#

ok then just stick with what you have

lost bloom
#

Thing is that the insturctions do call for getter and setter for each instance field

#

its worth half the grade😓

placid gyro
#

The professor may be using terminology incorrectly or not giving complete instructions.

#

That's unfortunate.

lost bloom
#

Im pretty sure the guy just got the assignment online and gave it to us

#

This wouldn't be the first time he does that

placid gyro
#

You should write him and ask him what he expects.

#

Is this high school or university?

#

or something else

lost bloom
#

its community college

#

its a 2 year university

placid gyro
#

ah, I went to community college a long time ago

#

The programming classes were hit or miss.

#

I'd definitely communicate with the professor and ask what he is expecting. Ask him if he wants you to use classes.

#

If it's worth half the grade I think it's important enough to bother him about it.

lost bloom
#

hopefully he answers my email

#

hes not very responsive

placid gyro
#

If he's not I'd consider going to the dean.

#

Contact some of your classmates.

#

If you're paying for an education you deserve to get one.

lost bloom
#

the fartherst this weeks chapter goes is storing fucntions into modules

placid gyro
#

modules?

lost bloom
#

according to the book a module is a file that contains python code

#

A module is simply a file that contains Python code. When you break a program into modules, each module should contain functions that perform related tasks. For example, suppose you are writing an accounting system. You would store all of the account receivable functions in their own module, all of the account payable functions in their own module, and all of the payroll functions in their own module. This approach, which is called modularization, makes the program easier to understand, test, and maintain.

#

this is the books explanation

placid gyro
#

that's fine

#
#

anyways, I would contact the professor and hopefully they will get back to you

lost bloom
#

Will do

#

thank for the advice

placid gyro
#

for sure, good luck with the class

queen merlinBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

🔒 Need help with Python homework