2

I know how to do an if statement and elif statement but in this particular code i don't know how. What im trying to do exactly is when the user puts either female or male and a temperature it will show an outfit for that weather depending which gender is chosen. Can anyone help me?

def main(): print("Welcome to Outfitters Boulevard!") print() print("Where your next vacation outfit is just around the corner.") print("================================================") name = input("What is your name?") gender = input("Are you male or female?") favoriteColor = input("What is your favorite color?") temp = int(input("What is the temperature like where you're going?")) print(name + ", you mentioned that you're a female, your favorite color is " + favoriteColor + ",") print("and you're going somewhere with " + str(temp) + " weather.") print("We've got just the outfit for you: ") if temp>84: print("The Perfect Hot Weather Outfit") elif 70 >=temp<= 84: print("The Perfect Warm Weather Outfit") elif 55>=temp<= 69: print("The Perfect Cool Weather Outfit") elif temp <55: print("The Perfect Cold Weather Outfit") main() 
5
  • Which outfit for which gender will show? Commented Jun 23, 2020 at 20:16
  • For "The perfect hot weather outfit" if the user was a female it would show shorts, sandals, sunhat and a crop shirt but if the user was a male it would show a hawaiian shirt, shorts and flip flops Commented Jun 23, 2020 at 20:18
  • 1
    Your comparison syntax is wrong. It should be elif 70 <= temp <= 84: Commented Jun 23, 2020 at 20:24
  • Note also that in the print statement with "you mentioned that you're a female", you should be using the gender variable you got from input Commented Jun 23, 2020 at 20:25
  • @anonymous123 I have answered your question, using the examples that you have provided. Commented Jun 23, 2020 at 20:25

6 Answers 6

1

I have edited your code to add nested if-statements and made it a little more user-friendly. I added the items like you asked and also guided you on how you would write other items:

def main(): print("Welcome to Outfitters Boulevard!") print() print("Where your next vacation outfit is just around the corner.") print("================================================") name = input("What is your name?") gender = input("Are you male or female or other?") favoriteColor = input("What is your favorite color?") temp = int(input("What is the temperature like where you're going?")) print(name + ", you mentioned that you're a female, your favorite color is " + favoriteColor + ",") print("and you're going somewhere with " + str(temp) + " weather.") print("We've got just the outfit for you: ") if temp>84: print("The Perfect Hot Weather Outfit") if gender.casefold() == 'male': # Show male outfits here print("Hawaiian shirt, shorts and flip flops") elif gender.casefold() == 'female': # Show female outfits here print("Shorts, sandals and a crop shirt.") else: # Show other outfits here elif 70 >=temp<= 84: print("The Perfect Warm Weather Outfit") if gender.casefold() == 'male': # Show male outfits here elif gender.casefold() == 'female': # Show female outfits here else: # Show other outfits here elif 55>=temp<= 69: print("The Perfect Cool Weather Outfit") if gender.casefold() == 'male': # Show male outfits here elif gender.casefold() == 'female': # Show female outfits here else: # Show other outfits here elif temp <55: print("The Perfect Cold Weather Outfit") if gender.casefold() == 'male': # Show male outfits here elif gender.casefold() == 'female': # Show female outfits here else: # Show other outfits here main() 

The casefold() method makes sure that capitals do not matter so the user can answer the gender question with varying capitals and still get to the output.

Sign up to request clarification or add additional context in comments.

Comments

1

Assuming the gender typed has to be either male or female, this should work.

On a sidenote this code is not very pretty and I recommend looking up f-strings to parse strings.

def main(): print("Welcome to Outfitters Boulevard!") print() print("Where your next vacation outfit is just around the corner.") print("================================================") name = input("What is your name?") gender = input("Are you male or female?") favoriteColor = input("What is your favorite color?") temp = int(input("What is the temperature like where you're going?")) print(name + ", you mentioned that you're a female, your favorite color is " + favoriteColor + ",") print("and you're going somewhere with " + str(temp) + " weather.") print("We've got just the outfit for you: ") # If it is a male if gender == "male": if temp>84: print("The Perfect Hot Weather Outfit") elif 70 >=temp<= 84: print("The Perfect Warm Weather Outfit") elif 55>=temp<= 69: print("The Perfect Cool Weather Outfit") elif temp <55: print("The Perfect Cold Weather Outfit") # if it is a female elif gender == "female": if temp>84: print("The Perfect Hot Weather Outfit") elif 70 >=temp<= 84: print("The Perfect Warm Weather Outfit") elif 55>=temp<= 69: print("The Perfect Cool Weather Outfit") elif temp <55: print("The Perfect Cold Weather Outfit") # If the gender is not correct else: print(f"Gender has to be male or female (found {gender})") main() 

Comments

0

Changes made in the conditions as well as added a gender check:

print("Welcome to Outfitters Boulevard!") print() print("Where your next vacation outfit is just around the corner.") print("================================================") name = input("What is your name?") gender = input("Are you male or female?") favoriteColor = input("What is your favorite color?") temp = int(input("What is the temperature like where you're going?")) if gender.lower() == "yes": gender = "female" else: gender = "male" print(name + ", you mentioned that you're a " + gender + ", your favorite color is " + favoriteColor + ",") print("and you're going somewhere with " + str(temp) + " weather.") print("We've got just the outfit for you: ") if temp > 84: print("The Perfect Hot Weather Outfit") elif temp >= 70 and temp <= 84: print("The Perfect Warm Weather Outfit") elif temp >= 55 and temp <= 69: print("The Perfect Cool Weather Outfit") elif temp < 55: print("The Perfect Cold Weather Outfit") 

OUTPUT:

================================================ What is your name?dirtybit Are you male or female?no What is your favorite color?black What is the temperature like where you're going?75 dirtybit, you mentioned that you're a male, your favorite color is black, and you're going somewhere with 75 weather. We've got just the outfit for you: The Perfect Warm Weather Outfit 

2 Comments

How is the user meant to know to input 'yes' or 'no' for the question: Are you male or female? I do not see how this part makes sense?
I'm sure you misread Are you male or female? as Are you female?.
0

You have to nest multiple if-statements:

if gender == "female": if temp>84: print("The Perfect Hot Weather Outfit") elif 70 >=temp<= 84: print("The Perfect Warm Weather Outfit") elif 55>=temp<= 69: print("The Perfect Cool Weather Outfit") elif temp <55: print("The Perfect Cold Weather Outfit") else: if temp>84: print("The Perfect Hot Weather Outfit") elif 70 >=temp<= 84: print("The Perfect Warm Weather Outfit") elif 55>=temp<= 69: print("The Perfect Cool Weather Outfit") elif temp <55: print("The Perfect Cold Weather Outfit") 

Comments

0

use and. in your case, it can be

elif temp >= 70 and temp <= 84: print("The Perfect Warm Weather Outfit") elif temp 55 >= and temp <= 69: print("The Perfect Cool Weather Outfit") elif temp < 55: print("The Perfect Cold Weather Outfit") 

Comments

0

Here is how you can add an if statement to
make the outputted outfit name be customized for males and females:

def main(): print("Welcome to Outfitters Boulevard!\n") print("Where your next vacation outfit is just around the corner.") print("================================================") name = input("What is your name?") gender = input("Are you male or female?") favoriteColor = input("What is your favorite color?") temp = int(input("What is the temperature like where you're going?")) print(f"{name}, you mentioned that you're a female, your favorite color is {favoriteColor},") print(f"and you're going somewhere with {temp} weather.") print("We've got just the outfit for you: ") if gender == 'female': # Here is where the customization begins gender = 'For Women' else: gender = 'For Men' if temp > 84: print(f"The Perfect Hot Weather Outfit {gender}") elif 70 <= temp <= 84: print(f"The Perfect Warm Weather Outfit {gender}") elif 55 <= temp <= 69: print(f"The Perfect Cool Weather Outfit {gender}") elif temp < 55: print(f"The Perfect Cold Weather Outfit {gender}") main() 

Input:

What is your name? Ann Zen Are you male or female? female What is your favorite color? red What is the temperature like where you're going? 70 

Output:

Ann Zen, you mentioned that you're a female, your favorite color is red, and you're going somewhere with 70 weather. We've got just the outfit for you: The Perfect Warm Weather Outfit For Women 

(note: You've goth the strict inequality operators mixed up, which I fixed here.)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.