Fix the Option
This function should return Option<&str> but it returns raw values. Fix it by wrapping returns in Some(...) and None.
Fix the code so it prints:
text
Grade for 95: A Grade for 50: unknown
Hint: Return Some("A") instead of "A", and None instead of "".
rust
fn grade(score: i32) -> Option<&'static str> {
if score >= 90 {
"A"
} else if score >= 80 {
"B"
} else if score >= 70 {
"C"
} else {
""
}
}
fn main() {
match grade(95) {
Some(g) => println!("Grade for 95: {}", g),
None => println!("Grade for 95: unknown"),
}
match grade(50) {
Some(g) => println!("Grade for 50: {}", g),
None => println!("Grade for 50: unknown"),
}
}