1 to 3 excercises

This commit is contained in:
Jorge Esparza 2026-02-20 23:56:39 -06:00
parent 87ac600b7c
commit 56b04dbc4d
16 changed files with 28 additions and 19 deletions

View File

@ -1,4 +1,4 @@
fn main() { fn main() {
// TODO: Fix the code to print "Hello world!". // TODO: Fix the code to print "Hello world!".
printline!("Hello world!"); println!("Hello world!");
} }

View File

@ -1,6 +1,6 @@
fn main() { fn main() {
// TODO: Add the missing keyword. // TODO: Add the missing keyword.
x = 5; let x = 5;
println!("x has the value {x}"); println!("x has the value {x}");
} }

View File

@ -1,8 +1,8 @@
fn main() { fn main() {
// TODO: Change the line below to fix the compiler error. // TODO: Change the line below to fix the compiler error.
let x; let x = 42;
if x == 10 { if 10 == x {
println!("x is ten!"); println!("x is ten!");
} else { } else {
println!("x is not ten!"); println!("x is not ten!");

View File

@ -1,6 +1,6 @@
fn main() { fn main() {
// TODO: Change the line below to fix the compiler error. // TODO: Change the line below to fix the compiler error.
let x: i32; let x: i32 = 42;
println!("Number {x}"); println!("Number {x}");
} }

View File

@ -1,6 +1,6 @@
// TODO: Fix the compiler error. // TODO: Fix the compiler error.
fn main() { fn main() {
let x = 3; let mut x = 3;
println!("Number {x}"); println!("Number {x}");
x = 5; // Don't change this line x = 5; // Don't change this line

View File

@ -3,6 +3,6 @@ fn main() {
println!("Spell a number: {number}"); println!("Spell a number: {number}");
// TODO: Fix the compiler error by changing the line below without renaming the variable. // TODO: Fix the compiler error by changing the line below without renaming the variable.
number = 3; let number2 = 3;
println!("Number plus two is: {}", number + 2); println!("Number plus two is: {}", number2 + 2);
} }

View File

@ -1,5 +1,5 @@
// TODO: Change the line below to fix the compiler error. // TODO: Change the line below to fix the compiler error.
const NUMBER = 3; const NUMBER: i32 = 3;
fn main() { fn main() {
println!("Number: {NUMBER}"); println!("Number: {NUMBER}");

View File

@ -1,5 +1,7 @@
// TODO: Add some function with the name `call_me` without arguments or a return value. // TODO: Add some function with the name `call_me` without arguments or a return value.
fn call_me() {
println!("You called me!");
}
fn main() { fn main() {
call_me(); // Don't change this line call_me(); // Don't change this line
} }

View File

@ -1,5 +1,5 @@
// TODO: Add the missing type of the argument `num` after the colon `:`. // TODO: Add the missing type of the argument `num` after the colon `:`.
fn call_me(num:) { fn call_me(num:u32) {
for i in 0..num { for i in 0..num {
println!("Ring! Call number {}", i + 1); println!("Ring! Call number {}", i + 1);
} }

View File

@ -6,5 +6,5 @@ fn call_me(num: u8) {
fn main() { fn main() {
// TODO: Fix the function call. // TODO: Fix the function call.
call_me(); call_me(1);
} }

View File

@ -8,7 +8,7 @@ fn is_even(num: i64) -> bool {
} }
// TODO: Fix the function signature. // TODO: Fix the function signature.
fn sale_price(price: i64) -> { fn sale_price(price: i64) -> i64{
if is_even(price) { if is_even(price) {
price - 10 price - 10
} else { } else {

View File

@ -1,6 +1,6 @@
// TODO: Fix the function body without changing the signature. // TODO: Fix the function body without changing the signature.
fn square(num: i32) -> i32 { fn square(num: i32) -> i32 {
num * num; num * num
} }
fn main() { fn main() {

View File

@ -4,6 +4,11 @@ fn bigger(a: i32, b: i32) -> i32 {
// Do not use: // Do not use:
// - another function call // - another function call
// - additional variables // - additional variables
if a > b {
a
} else {
b
}
} }
fn main() { fn main() {

View File

@ -2,8 +2,10 @@
fn picky_eater(food: &str) -> &str { fn picky_eater(food: &str) -> &str {
if food == "strawberry" { if food == "strawberry" {
"Yummy!" "Yummy!"
} else if food == "potato" {
"I guess I can eat that."
} else { } else {
1 "No thanks!"
} }
} }

View File

@ -1,13 +1,13 @@
fn animal_habitat(animal: &str) -> &str { fn animal_habitat(animal: &str) -> &str {
// TODO: Fix the compiler error in the statement below. // TODO: Fix the compiler error in the statement below.
let identifier = if animal == "crab" { let identifier = if animal == "crab" {
1 1
} else if animal == "gopher" { } else if animal == "gopher" {
2.0 2
} else if animal == "snake" { } else if animal == "snake" {
3 3
} else { } else {
"Unknown" 4
}; };
// Don't change the expression below! // Don't change the expression below!

View File

@ -4,7 +4,7 @@
set -e set -e
typos typos
cargo upgrades # cargo upgrades
# Similar to CI # Similar to CI
cargo clippy -- --deny warnings cargo clippy -- --deny warnings