Asked by dave
def sunny():
print("Wear sandals.")
def raniy():
print("Wear galoshes.")
def snowy():
print("Wear boots.")
weather = input("What time of day is it? (sunny, rainy, snowy): ")
if weather == "sunny":
sunny()
elif weather == "raniy":
raniy()
elif weather == "snowy":
snowy()
else:
print("Invalid option.")
All Answers 1
Answered by
GPT-5 mini
AI
You have a small typo and a confusing prompt string.
Problems:
- The function and elif for "rainy" are spelled "raniy" (mismatch causes that branch never to run).
- The input prompt asks for "What time of day is it?" though you want the weather.
Here's a corrected minimal version:
```python
def sunny():
print("Wear sandals.")
def rainy():
print("Wear galoshes.")
def snowy():
print("Wear boots.")
weather = input("What is the weather? (sunny, rainy, snowy): ").strip().lower()
if weather == "sunny":
sunny()
elif weather == "rainy":
rainy()
elif weather == "snowy":
snowy()
else:
print("Invalid option.")
```
Improvements you might consider:
- Use a dict to map inputs to actions to reduce repeated if/elif.
- Use .strip().lower() (already shown) to handle extra whitespace and capitalization.
- Loop until a valid option is entered if you want to force valid input.
If you want, I can show the dict-based version or add a retry loop. Which would you prefer?
Problems:
- The function and elif for "rainy" are spelled "raniy" (mismatch causes that branch never to run).
- The input prompt asks for "What time of day is it?" though you want the weather.
Here's a corrected minimal version:
```python
def sunny():
print("Wear sandals.")
def rainy():
print("Wear galoshes.")
def snowy():
print("Wear boots.")
weather = input("What is the weather? (sunny, rainy, snowy): ").strip().lower()
if weather == "sunny":
sunny()
elif weather == "rainy":
rainy()
elif weather == "snowy":
snowy()
else:
print("Invalid option.")
```
Improvements you might consider:
- Use a dict to map inputs to actions to reduce repeated if/elif.
- Use .strip().lower() (already shown) to handle extra whitespace and capitalization.
- Loop until a valid option is entered if you want to force valid input.
If you want, I can show the dict-based version or add a retry loop. Which would you prefer?
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.