mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-28 06:49:19 +00:00
fix base use
This commit is contained in:
parent
0f4cb94cfe
commit
a2e9d3cae7
@ -1,4 +1,4 @@
|
||||
fn main() {
|
||||
// TODO: Fix the code to print "Hello world!".
|
||||
printline!("Hello world!");
|
||||
println!("Hello world!");
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
fn main() {
|
||||
// TODO: Add missing keyword.
|
||||
x = 5;
|
||||
let x: i32 = 5;
|
||||
|
||||
println!("x has the value {x}");
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
fn main() {
|
||||
// TODO: Change the line below to fix the compiler error.
|
||||
let x;
|
||||
let x: i32 = 10;
|
||||
|
||||
if x == 10 {
|
||||
println!("x is ten!");
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
fn main() {
|
||||
// TODO: Change the line below to fix the compiler error.
|
||||
let x: i32;
|
||||
let x: i32 = 10;
|
||||
|
||||
println!("Number {x}");
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// TODO: Fix the compiler error.
|
||||
fn main() {
|
||||
let x = 3;
|
||||
let mut x: i32 = 3;
|
||||
println!("Number {x}");
|
||||
|
||||
x = 5; // Don't change this line
|
||||
|
||||
@ -3,6 +3,6 @@ fn main() {
|
||||
println!("Spell a number: {}", number);
|
||||
|
||||
// TODO: Fix the compiler error by changing the line below without renaming the variable.
|
||||
number = 3;
|
||||
let number = 3;
|
||||
println!("Number plus two is: {}", number + 2);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
// TODO: Change the line below to fix the compiler error.
|
||||
const NUMBER = 3;
|
||||
const NUMBER: i32 = 3;
|
||||
|
||||
fn main() {
|
||||
println!("Number: {NUMBER}");
|
||||
|
||||
@ -3,3 +3,5 @@
|
||||
fn main() {
|
||||
call_me(); // Don't change this line
|
||||
}
|
||||
|
||||
fn call_me(){}
|
||||
@ -1,5 +1,5 @@
|
||||
// TODO: Add the missing type of the argument `num` after the colon `:`.
|
||||
fn call_me(num:) {
|
||||
fn call_me(num: i32) {
|
||||
for i in 0..num {
|
||||
println!("Ring! Call number {}", i + 1);
|
||||
}
|
||||
|
||||
@ -6,5 +6,5 @@ fn call_me(num: u32) {
|
||||
|
||||
fn main() {
|
||||
// TODO: Fix the function call.
|
||||
call_me();
|
||||
call_me(3);
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ fn is_even(num: i64) -> bool {
|
||||
}
|
||||
|
||||
// TODO: Fix the function signature.
|
||||
fn sale_price(price: i64) -> {
|
||||
fn sale_price(price: i64) -> i64 {
|
||||
if is_even(price) {
|
||||
price - 10
|
||||
} else {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// TODO: Fix the function body without changing the signature.
|
||||
fn square(num: i32) -> i32 {
|
||||
num * num;
|
||||
num * num
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@ -4,6 +4,7 @@ fn bigger(a: i32, b: i32) -> i32 {
|
||||
// Do not use:
|
||||
// - another function call
|
||||
// - additional variables
|
||||
if a > b { a } else { b }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@ -2,8 +2,10 @@
|
||||
fn foo_if_fizz(fizzish: &str) -> &str {
|
||||
if fizzish == "fizz" {
|
||||
"foo"
|
||||
} else if fizzish == "fuzz" {
|
||||
"bar"
|
||||
} else {
|
||||
1
|
||||
"baz"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,11 +3,11 @@ fn animal_habitat(animal: &str) -> &str {
|
||||
let identifier = if animal == "crab" {
|
||||
1
|
||||
} else if animal == "gopher" {
|
||||
2.0
|
||||
2
|
||||
} else if animal == "snake" {
|
||||
3
|
||||
} else {
|
||||
"Unknown"
|
||||
4
|
||||
};
|
||||
|
||||
// Don't change the expression below!
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user