if,functions,primitives,test1
This commit is contained in:
parent
8cc68ff891
commit
86913c4d03
|
@ -5,10 +5,9 @@ fn main() {
|
|||
call_me();
|
||||
}
|
||||
|
||||
fn call_me() {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ fn main() {
|
|||
call_me(3);
|
||||
}
|
||||
|
||||
fn call_me(num) {
|
||||
fn call_me(num: i32) {
|
||||
for i in 0..num {
|
||||
println!("Ring! Call number {}", i + 1);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Make me compile! Scroll down for hints :)
|
||||
|
||||
fn main() {
|
||||
call_me();
|
||||
call_me(5);
|
||||
}
|
||||
|
||||
fn call_me(num: i32) {
|
||||
|
|
|
@ -9,7 +9,7 @@ fn main() {
|
|||
println!("Your sale price is {}", sale_price(original_price));
|
||||
}
|
||||
|
||||
fn sale_price(price: i32) -> {
|
||||
fn sale_price(price: i32) -> i32 {
|
||||
if is_even(price) {
|
||||
price - 10
|
||||
} else {
|
||||
|
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn square(num: i32) -> i32 {
|
||||
num * num;
|
||||
num * num
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,12 @@ pub fn bigger(a: i32, b:i32) -> i32 {
|
|||
// - another function call
|
||||
// - additional variables
|
||||
// Scroll down for hints.
|
||||
if a > b {
|
||||
a
|
||||
}
|
||||
else {
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
// Don't mind this for now :)
|
||||
|
|
|
@ -10,7 +10,7 @@ fn main() {
|
|||
println!("Good morning!");
|
||||
}
|
||||
|
||||
let // Finish the rest of this line like the example! Or make it be false!
|
||||
let is_evening = false; // Finish the rest of this line like the example! Or make it be false!
|
||||
if is_evening {
|
||||
println!("Good evening!");
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@ fn main() {
|
|||
println!("Neither alphabetic nor numeric!");
|
||||
}
|
||||
|
||||
let // Finish this line like the example! What's your favorite character?
|
||||
let your_character = '1';
|
||||
// Finish this line like the example! What's your favorite character?
|
||||
// Try a letter, try a number, try a special character, try a character
|
||||
// from a different language than your own, try an emoji!
|
||||
if your_character.is_alphabetic() {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// Scroll down for hints!
|
||||
|
||||
fn main() {
|
||||
let a = ???
|
||||
let a = [0..100];
|
||||
|
||||
if a.len() >= 100 {
|
||||
println!("Wow, that's a big array!");
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
fn main() {
|
||||
let a = [1, 2, 3, 4, 5];
|
||||
|
||||
let nice_slice = ???
|
||||
let nice_slice = &a[1..4];
|
||||
|
||||
if nice_slice == [2, 3, 4] {
|
||||
println!("Nice slice!");
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
fn main() {
|
||||
let cat = ("Furry McFurson", 3.5);
|
||||
let /* your pattern here */ = cat;
|
||||
let (name, age) = cat;
|
||||
|
||||
println!("{} is {} years old.", name, age);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
fn main() {
|
||||
let numbers = (1, 2, 3);
|
||||
println!("The second number is {}", ???);
|
||||
println!("The second number is {}", numbers.1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,14 @@
|
|||
// Put your function here!
|
||||
// fn ..... {
|
||||
|
||||
fn calculateprice(amount: i32) -> i32 {
|
||||
if amount <= 40 {
|
||||
amount*2
|
||||
}
|
||||
else {
|
||||
amount
|
||||
}
|
||||
}
|
||||
// Don't modify this function!
|
||||
#[test]
|
||||
fn verify_test() {
|
||||
|
|
Loading…
Reference in a new issue