In this challenge, you will create a function that determines the characteristics of a given number. Specifically, the function will evaluate whether a number is positive negative, or zero and also determine if it is even or odd.
Rust's powerful control flow mechanisms, including if, else if, and else statements, make it easy to handle multiple conditions. By combining these conditions with logical operators, you can create a function that provides comprehensive information about the number.
You are given a function describe_number(n: i32) -> String that takes an integer as input and returns a string description of the number's characteristics. The description should include whether the number is positive, negative, or zero and whether it is even or odd.
For example:
Complete the function by implementing the necessary conditions and logical checks.
let result = describe_number(10);
assert_eq!(result, "Positive even");
let result = describe_number(-3);
assert_eq!(result, "Negative odd");
let result = describe_number(0);
assert_eq!(result, "Zero");% can help determine if a number is even or odd.&& and || will be useful for combining conditions.pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n == 0 { return String::from("Zero"); } if n % 2 == 0 { if n < 0 { return String::from("Negative even"); } else { return String::from("Positive even"); } } else { if n < 0 { return String::from("Negative odd"); } else { return String::from("Positive odd"); } }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n < 0 { if n % 2 == 0 { "Negative even".to_owned() } else { "Negative odd".to_owned() } } else if n > 0 { if n % 2 == 0 { "Positive even".to_owned() } else { "Positive odd".to_owned() } } else { "Zero".to_owned() }}pub fn describe_number(n: i32) -> String { println!("{}", n); match n { n if n > 0 && n % 2 == 0 => { return "Positive even".to_string(); } n if n > 0 && n % 2 == 1 => { return "Positive odd".to_string(); } n if n < 0 && n % 2 == 0 => { return "Negative even".to_string(); } n if n < 0 && n % 2 == -1 => { return "Negative odd".to_string(); } _ => { return "Zero".to_string(); } }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n == 0 { "Zero".to_string() } else if n > 0 { if n % 2 == 0 { "Positive even".to_string() } else { "Positive odd".to_string() } } else { if n % 2 == 0 { "Negative even".to_string() } else { "Negative odd".to_string() } }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n == 0 { return "Zero".to_string(); } match (n > 0, n % 2 == 0) { (true, true) => "Positive even".to_string(), (true, false) => "Positive odd".to_string(), (false, true) => "Negative even".to_string(), (false, false) => "Negative odd".to_string(), }}pub fn describe_number(n: i32) -> String { match (n, n > 0, n % 2 == 0) { (0, _, _) => "Zero".to_string(), (_, true, true) => "Positive even".to_string(), (_, true, false) => "Positive odd".to_string(), (_, false, true) => "Negative even".to_string(), (_, false, false) => "Negative odd".to_string(), }}pub fn describe_number(n: i32) -> String { let mut vec = Vec::new(); if n > 0 { vec.push("Positive"); } else if n < 0 { vec.push("Negative") } else { return "Zero".to_string(); } if n % 2 == 0 { vec.push("even"); } else { vec.push("odd"); } vec.join(" ").to_string()}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n == 0 { "Zero".to_string() } else { format!("{} {}", if n > 0 { "Positive" } else { "Negative" }, if n % 2 == 0 { "even" } else { "odd" } ) }}pub fn describe_number(n: i32) -> String { if n == 0 { return String::from("Zero"); } let mut r = String::new(); if n < 0 { r.push_str("Negative"); } else { r.push_str("Positive"); } if n % 2 == 0 { r.push_str(" even"); } else { r.push_str(" odd"); } r}pub fn describe_number(n: i32) -> String { match n { 0 => "Zero".into(), 1.. if n % 2 == 0 => "Positive even".into(), 1.. if n % 2 != 0 => "Positive odd".into(), ..=0 if n % 2 == 0 => "Negative even".into(), ..=0 if n % 2 != 0 => "Negative odd".into(), _ => unreachable!(), }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here let result = if n>0 { if n%2==0{ "Positive even" }else{ "Positive odd" } }else if n<0{ if n%2==0{ "Negative even" }else{ "Negative odd" } }else{ "Zero" }; result.to_string()}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here let result = if n>0 { if n%2==0{ "Positive even" }else{ "Positive odd" } }else if n<0{ if n%2==0{ "Negative even" }else{ "Negative odd" } }else{ "Zero" }; result.to_string()}pub fn describe_number(n: i32) -> String { let mut result:String = String::new(); if n > 0 { result.push_str("Positive"); } else if n < 0 { result.push_str("Negative"); } else { result.push_str("Zero"); return result; } if n % 2 == 0 { result.push_str(" even"); } else { result.push_str(" odd"); } result}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here let sign = if n > 0 { "Positive" } else if n < 0 { "Negative" } else { "Zero" }; let parity = if n % 2 == 0 { "even" } else { "odd" }; if n == 0 { "Zero".to_string() } else { format!("{} {}", sign, parity) }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here let mut ans: String = String::new(); match n { n if n < 0 => ans += "Negative ", n if n > 0 => ans += "Positive ", _ => ans += "Zero", } if ans == "Zero" {return ans;} match n{ n if n%2 == 0 => ans += "even", _ => ans += "odd", } ans}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here let mut ans: String = String::new(); match n { n if n < 0 => { ans += "Negative "; if n % 2 == 0 { ans += "even"; } else { ans += "odd"; } }, n if n > 0 => { ans += "Positive "; if n % 2 == 0 { ans += "even"; } else { ans += "odd"; } } _ => ans += "Zero", } ans}pub fn describe_number(n: i32) -> String { match (n, n % 2 == 0, n < 0) { (0, _, _) => "Zero", (_, true, true) => "Negative even", (_, true, false) => "Positive even", (_, false, true) => "Negative odd", (_, false, false) => "Positive odd", }.to_string()}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n == 0 { return String::from("Zero"); } else if n % 2 == 0 { if n > 0 { return String::from("Positive even"); } else { return String::from("Negative even"); } } else { if n > 0 { return String::from("Positive odd"); } else { return String::from("Negative odd"); } }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here let mut descritpion:String=String::new(); if n>0{ descritpion+= "Positive "; }else if n<0{ descritpion+="Negative "; }else{ return "Zero".to_string(); } if n%2==0{ descritpion+= "even"; }else{ descritpion+= "odd"; } descritpion}pub fn describe_number(n: i32) -> String { let mut result = String::from("Zero"); if n == 0 { return result; } if n > 0 { result = "Positive ".to_string(); } else { result = "Negative ".to_string(); } if n % 2 == 0 { result.push_str("even"); } else { result.push_str("odd") } result}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n == 0 { return "Zero".to_string(); } let mut pn = "Positive"; if n < 0 { pn = "Negative"; } let mut eo = "even"; if n % 2 != 0 { eo = "odd"; } format!("{} {}", pn, eo).to_string()}pub fn describe_number(n: i32) -> String { if n == 0 {return "Zero".to_string();} let mut out = String::new(); if n > 0 {out += "Positive";} else {out += "Negative";} if n%2 == 0 {out += " even";} else {out += " odd";} out.to_string()}pub fn describe_number(n: i32) -> String { let mut result; if n > 0 { result = String::from("Positive"); } else if n < 0 { result = String::from("Negative") } else { return String::from("Zero"); } if n%2 == 0 { result.push_str(" even"); } else { result.push_str(" odd"); } result}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here match (n, n > 0, n % 2 == 0) { (0, _, _) => "Zero".into(), (_, true, true) => "Positive even".into(), (_, true, false) => "Positive odd".into(), (_, false, true) => "Negative even".into(), _ => "Negative odd".into(), }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n % 2 == 0 && n > 0 { "Positive even".to_string() } else if n % 2 != 0 && n > 0 { "Positive odd".to_string() } else if n % 2 == 0 && n < 0 { "Negative even".to_string() } else if n % 2 != 0 && n < 0 { "Negative odd".to_string() } else { "Zero".to_string() }}pub fn describe_number(n: i32) -> String { match (n, n > 0, n % 2 == 0) { (0, _, _) => "Zero".into(), (_, true, true) => "Positive even".into(), (_, true, false) => "Positive odd".into(), (_, false, true) => "Negative even".into(), _ => "Negative odd".into(), }}pub fn describe_number(n: i32) -> String { if n==0 {return "Zero".to_string();} let mut out = String::new(); out += if n<0 {"Negative "} else {"Positive "}; out += if n%2 == 0 {"even"} else {"odd"}; return out;}pub fn describe_number(n: i32) -> String { if n==0 {return "Zero".to_string();} let mut out = String::new(); out += if n<0 {"Negative "} else {"Positive "}; out += if n%2 == 0 {"even"} else {"odd"}; return out;}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here let mut ans = if n > 0 { "Positive".to_string() } else if n < 0 { "Negative".to_string() } else { return "Zero".to_string(); }; if n % 2 == 0 { ans.push_str(" even"); } else { ans.push_str(" odd"); } ans}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n > 0 && n % 2 == 0 { "Positive even".to_string() } else if n % 2 != 0 && n > 0 { "Positive odd".to_string() } else if n < 0 && n % 2 != 0 { "Negative odd".to_string() } else if n < 0 && n % 2 == 0 { "Negative even".to_string() } else { "Zero".to_string() }}pub fn describe_number(n: i32) -> String { if n == 0 { return "Zero".to_string(); } let sign = if n > 0 { "Positive" } else { "Negative" }; let parity = if n % 2 == 0 { "even" } else { "odd" }; format!("{} {}", sign, parity)}pub fn describe_number(n: i32) -> String { if n == 0 { return "Zero".to_string(); } let mut s: String = "".to_string(); if n > 0 { s.push_str("Positive"); } else { s.push_str("Negative"); } if n % 2 == 0 { s.push_str(" even"); } else { s.push_str(" odd"); } s}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n == 0 { return "Zero".into(); } match (n > 0, n%2 == 0) { (true, true) => "Positive even".into(), (true, false) => "Positive odd".into(), (false, true) => "Negative even".into(), (false, false) => "Negative odd".into(), }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here /*match (n>0, n<0, n%2==0) { (true, false, true) => "Positive even", (true, false, false) => "Positive odd", (false, true, true) => "Negative even", (false, true, false) => "Negative odd", _ => "Zero", }.to_string()*/ if n > 0 { format!("Positive {}", if n % 2 == 0 {"even"} else {"odd"} ) } else if n < 0 { format!("Negative {}", if n % 2 == 0 {"even"} else {"odd"} ) } else { "Zero".to_string() } }pub fn describe_number(n: i32) -> String { // TODO: Implement the function here match (n>0, n<0, n%2==0) { (true, false, true) => "Positive even", (true, false, false) => "Positive odd", (false, true, true) => "Negative even", (false, true, false) => "Negative odd", _ => "Zero", }.to_string()}pub fn describe_number(n: i32) -> String { if n == 0 { return "Zero".to_string(); } (if n > 0 { "Positive" } else { "Negative" }).to_string() + (if n % 2 == 0 { " even" } else { " odd" }) }pub fn describe_number(n: i32) -> String { // TODO: Implement the function he match n { n if n == 0 => "Zero".to_string(), n if n < 0 && n % 2 == 0 => "Negative even".to_string(), n if n > 0 && n % 2 == 0 => "Positive even".to_string(), n if n < 0 && n % 2 != 0 => "Negative odd".to_string(), n if n > 0 && n % 2 != 0 => "Positive odd".to_string(), _ => "".to_string(), }}pub fn describe_number(n: i32) -> String { match n { 0 => "Zero".to_string(), _ => match n > 0 { true => match n % 2 == 0 { true => "Positive even".to_string(), false => "Positive odd".to_string(), }, false => match n % 2 == 0 { true => "Negative even".to_string(), false => "Negative odd".to_string(), }, }, }}pub fn describe_number(n: i32) -> String { match n { 0 => "Zero".to_string(), n if n % 2 == 0 && n > 0 => "Positive even".to_string(), n if n % 2 != 0 && n > 0 => "Positive odd".to_string(), n if n % 2 == 0 && n < 0 => "Negative even".to_string(), n if n % 2 != 0 && n < 0 => "Negative odd".to_string(), _ => unreachable!(), }}pub fn describe_number(n: i32) -> String { if n == 0 { return "Zero".to_string() } else if n % 2 == 0 && n > 0 { return "Positive even".to_string() } else if n % 2 == 0 && n < 0 { return "Negative even".to_string() } else if n < 0 { return "Negative odd".to_string() } else { return "Positive odd".to_string() }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n > 0 && n % 2 == 0 { "Positive even".to_string() } else if n > 0 && n % 2 != 0 { "Positive odd".to_string() } else if n < 0 && n % 2 == 0 { "Negative even".to_string() } else if n < 0 && n % 2 != 0 { "Negative odd".to_string() } else if n == 0 { "Zero".to_string() } else { "Please input the correct number".to_string() }}pub fn describe_number(n: i32) -> String { match n { 0 => "Zero".to_string(), n if n >= 0 && n % 2 == 0 => "Positive even".to_string(), n if n >= 0 && n % 2 != 0 => "Positive odd".to_string(), n if n <= 0 && n % 2 == 0 => "Negative even".to_string(), n if n <= 0 && n % 2 != 0 => "Negative odd".to_string(), _ => unimplemented!(), }}pub fn describe_number(n: i32) -> String { if n == 0 { return "Zero".to_string(); } let mut result : String = String::new(); result += if n > 0 { "Positive " } else { "Negative " }; result += if n % 2 == 0 {"even"} else {"odd"}; return result; }pub fn describe_number(n: i32) -> String { match n { n if n < 0 && n % 2 == 0 => format!("Negative even"), n if n < 0 && n % 2 != 0 => format!("Negative odd"), n if n > 0 && n % 2 == 0 => format!("Positive even"), n if n > 0 && n % 2 != 0 => format!("Positive odd"), n if n == 0 => format!("Zero"), _ => unimplemented!(), }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n == 0{ return "Zero".to_string(); } let mut out = String::new(); if n > 0{ out.push_str("Positive "); }else{ out.push_str("Negative "); } if n % 2 == 0{ out.push_str("even"); }else{ out.push_str("odd"); } out}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here match n { 0 => "Zero".to_string(), n if n % 2 == 0 => { if n > 0 { "Positive even".to_string() }else { "Negative even".to_string() } }, n if n % 2 == 1 || n % 2 == -1=> { if n > 0 { "Positive odd".to_string() } else { "Negative odd".to_string() } }, _ => "Fault".to_string(), }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here let description ; if n == 0 { return "Zero".to_string(); } if n > 0 { description = "Positive"; } else { description = "Negative"; } if n % 2 == 0 { return (description.to_owned() + " even").to_string(); } else { return (description.to_owned() + " odd").to_string(); }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n > 0 { format!("Positive {}", if n % 2 == 0 {"even"} else {"odd"} ) } else if n < 0 { format!("Negative {}", if n % 2 == 0 {"even"} else {"odd"} ) } else {"Zero".to_string()} }pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n > 0 { if n%2 == 0 { "Positive even".to_string() } else { "Positive odd".to_string() } } else if n < 0 { if n%2 == 0 { "Negative even".to_string() } else { "Negative odd".to_string() } } else { "Zero".to_string() }}pub fn describe_number(n: i32) -> String { // TODO: Implement the function here if n==0{ "Zero".to_string() } else if n>0{ if n%2==0{ "Positive even".to_string() } else { "Positive odd".to_string() } } else { if n%2==0{ "Negative even".to_string() } else { "Negative odd".to_string() } }}