How to make ideal_weight variable with if(depends on sex) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to make ideal_weight variable with if(depends on sex)

Hello. I want to define ideal_weight variable based on sex (if boy, height-K_boy, if girl, height-K_girl) How do i express the syntax? name= str(input()) sex= str(input()) weight= int(input()) height= int(input()) K_boy= int(100) K_girl= int(110) ideal_weight = int(height-K_girl) print("what is your name? ") print(name) print("are you a boy or a girl? ") print(sex) print("what is your height? ") print(height) print("your ideal weight is: ") if sex == "boy" : print(height-100) elif sex == "girl" : print(height-110) if sex == "girl" and weight < ideal_weight : print("you are skinny") elif sex == "girl" and weight > ideal_weight : print("you are fat")

10th Sep 2019, 2:44 PM
Satria Hutama Priyadi
Satria Hutama Priyadi - avatar
4 Answers
+ 6
This is your code, just letting you know that you can link it. Also, you might want to try to refrain from using terms (in this case, "b*tch") which may be considered offensive by the majority of people. https://code.sololearn.com/cq2zgfk4Wi5S/?ref=app
10th Sep 2019, 3:07 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Satria Hutama Priyadi Well, your syntax is arguably correct, just a few redundancies here and there. The input() function returns a string, so there's no need to cast it to string using str() again. Likewise, since 100 and 110 are numeric literals, there's no need to cast them to int. You might want to take input when asking the question instead of asking the question later, e.g. name = input("what is your name?") Since you have variables K_boy and K_girl, might as well use them in your if statements. if sex == "boy": print(height - K_boy) ^ I think this is what your query is really about. (Do you want to store the resulting value in a variable like you did, using ideal_weight?) The remaining problem with the code is that, I'm not sure if the formula for the ideal weight is correct (?). What happens if my height is below 100? :o Syntax-wise, just make the changes to the parts I mentioned and you should be close to what you want.
10th Sep 2019, 3:40 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Ok thank you for the reply. This is just a test after 2 days with phyton learning.. just want to put it into practice :,-)
11th Sep 2019, 5:26 AM
Satria Hutama Priyadi
Satria Hutama Priyadi - avatar
0
Ok sorry if i offend anyone. Just trying to put some humor Hatsy Rei can you help solve my problem defining the variable ideal_weight using if boy= height-K_boy, if girl=height-k_girl
10th Sep 2019, 3:32 PM
Satria Hutama Priyadi
Satria Hutama Priyadi - avatar