实现天气建议函数
你的任务是实现 weatherAdvice 函数,使用 switch 语句针对不同的天气状况提供相应的着装建议。
任务
- 编写一个名为
weatherAdvice 的函数,该函数接收一个 string 类型的参数(天气状况)。
- 使用
switch 语句为至少四种天气状况提供建议:snow(雪)、rain(雨)、sunny(晴)和 cloudy(阴)。
- 包含一个
default 分支来处理无法识别的天气状况。
- 使用
fmt.Println() 为每种状况打印具体的着装建议。
要求
- 在
~/project/weather_advice.go 文件中实现 weatherAdvice 函数。
- 使用提供的
main 函数来测试 weatherAdvice 函数。
- 雪天(snow)的建议中必须包含
coat(外套)。
- 雨天(rain)的建议中必须包含
umbrella(雨伞)。
- 晴天(sunny)的建议中必须包含
sunglasses(太阳镜)。
- 阴天(cloudy)的建议中必须包含
jacket(夹克)。
- 默认分支(default case)应当打印一条信息,提示该天气状况无法识别。
示例输出
运行程序时,输出结果应如下所示:
go run weather_advice.go
--- Testing Weather Advice Function ---
For condition: Snow
Remember to wear a warm coat and snow boots! 🧣
For condition: Rain
Don't forget your umbrella and waterproof jacket! 🌂
For condition: Sunny
Wear sunglasses and light clothing! ☀️
For condition: Cloudy
A light jacket might be a good idea. ☁️
For condition: Unknown
Weather condition not recognized. Stay prepared!