Skip to content

Commit

Permalink
adding println
Browse files Browse the repository at this point in the history
  • Loading branch information
country cousin authored and country cousin committed Mar 4, 2024
1 parent 7b00b43 commit 4afa59f
Show file tree
Hide file tree
Showing 30 changed files with 76 additions and 58 deletions.
1 change: 1 addition & 0 deletions exercises/arrays/arrays3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ fn test_arrays3() {
// You should not change the index accessed.
a.at(2);
}

2 changes: 1 addition & 1 deletion exercises/dict/dict2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
fn multiply_element_by_10(ref dict: Felt252Dict<u32>, n: usize) {
//TODO : make a function that multiplies the elements stored at the indexes 0 to n of a dictionary by 10


}

// Don't change anything in the test
Expand Down
11 changes: 6 additions & 5 deletions exercises/enums/enums1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// I AM NOT DONE

use debug::print;

use debug::PrintTrait;
enum Message { // TODO: define a few types of messages as used below
}
Expand All @@ -18,10 +18,11 @@ fn main() {
impl MessagePrintImpl of PrintTrait<Message> {
fn print(self: Message) {
match self {
Message::Quit => ('Quit').print(),
Message::Echo => ('Echo').print(),
Message::Move => ('Move').print(),
Message::ChangeColor => ('ChangeColor').print()

Message::Quit => println!("Quit"),
Message::Echo => println!("Echo"),
Message::Move => println!("Move"),
Message::ChangeColor => println!("ChangeColor")
}
}
}
18 changes: 9 additions & 9 deletions exercises/enums/enums2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ fn print_messages_recursive(messages: Array<Message>, index: u32) {

impl MessagePrintImpl of PrintTrait<Message> {
fn print(self: Message) {
('___MESSAGE BEGINS___').print();
println!("___MESSAGE BEGINS___");
match self {
Message::Quit => ('Quit').print(),
Message::Echo(msg) => msg.print(),
Message::Quit => println!("Quit"),
Message::Echo(msg) => println!("{}", msg),
Message::Move((a, b)) => {
a.print();
b.print();
println!("{}", a);
println!("{}",b);
},
Message::ChangeColor((red, green, blue)) => {
red.print();
green.print();
blue.print();
println!("{}",red);
println!("{}",green);
println!("{}",blue);
}
}
('___MESSAGE ENDS___').print();
println!("___MESSAGE ENDS___");
}
}
4 changes: 2 additions & 2 deletions exercises/enums/enums3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Address all the TODOs to make the tests pass!
// Execute `starklings hint enums3` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE
// I AM NOT DONE print

use debug::PrintTrait;

Expand Down Expand Up @@ -41,7 +41,7 @@ impl StateImpl of StateTrait {
}

fn echo(ref self: State, s: felt252) {
s.print();
println!("{}", s);
}

fn move_position(ref self: State, p: Point) {
Expand Down
3 changes: 1 addition & 2 deletions exercises/functions/functions2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// Execute `starklings hint functions2` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE
use debug::PrintTrait;

fn main() {
call_me(3);
}

fn call_me(num:) {
num.print();
println!("num is {}", num);
}
5 changes: 3 additions & 2 deletions exercises/functions/functions3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Execute `starklings hint functions3` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE
use debug::PrintTrait;


fn main() {
call_me();
}

fn call_me(num: u64) {
num.print();

println!("num is {}", num);
}
4 changes: 2 additions & 2 deletions exercises/functions/functions4.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// to future exercises!)

// I AM NOT DONE
use debug::PrintTrait;


fn main() {
let original_price = 51;
sale_price(original_price).print();
println!("sale_price is {}", sale_price(original_price));
}

fn sale_price(price: u32) -> {
Expand Down
1 change: 1 addition & 0 deletions exercises/if/if1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ mod tests {
assert(42 == bigger(32, 42), '42 bigger than 32');
}
}

2 changes: 1 addition & 1 deletion exercises/if/if2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ mod tests {
fn default_to_baz() {
assert(foo_if_fizz('literally anything') == 'baz', 'anything else returns baz');
}
}
}
1 change: 1 addition & 0 deletions exercises/intro/intro2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// This exercise won't compile... Can you make it compile?


fn main(){}
2 changes: 1 addition & 1 deletion exercises/loops/loops2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ fn test_loop() {
};

assert(result == 5, 'result should be 5');
}
}
1 change: 1 addition & 0 deletions exercises/modules/modules1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ mod tests {
assert(order_result == 'order_taken', 'Order not taken');
}
}

2 changes: 1 addition & 1 deletion exercises/modules/modules2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// These modules have some issues, can you fix?
// Run `starklings hint modules2` or `hint` watch command for a hint.

use debug::PrintTrait;
// use debug::PrintTrait;
const YEAR: u16 = 2050;

mod order {
Expand Down
1 change: 0 additions & 1 deletion exercises/operations/operations1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// TODO
// Return the solution of x^3 + y - 2

use debug::PrintTrait;

fn poly(x: usize, y: usize) -> usize {
// FILL ME
Expand Down
4 changes: 2 additions & 2 deletions exercises/options/options2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// I AM NOT DONE

use option::OptionTrait;
use debug::PrintTrait;


#[test]
fn test_options() {
Expand All @@ -19,5 +19,5 @@ fn simple_option(optional_target: Option<felt252>) {
// TODO: use the `is_some` and `is_none` methods to check if `optional_target` contains a value.
// Place the assertion and the print statement below in the correct blocks.
assert(optional_target.unwrap() == 'starklings', 'err1');
('option is empty !').print();
println!(" option is empty ! ");
}
6 changes: 4 additions & 2 deletions exercises/options/options3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// I AM NOT DONE

use option::OptionTrait;
use debug::PrintTrait;
use array::ArrayTrait;

#[derive(Drop)]
Expand Down Expand Up @@ -41,8 +40,11 @@ fn display_grades(student: @Student, index: usize) {
// TODO: Modify the following lines so that if there is a grade for the course, it is printed.
// Otherwise, print "No grade".
//
course.unwrap().print();

println!("grade is {}", course.unwrap());
display_grades(student, index + 1);


}


Expand Down
8 changes: 5 additions & 3 deletions exercises/primitive_types/primitive_types1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

// I AM NOT DONE

use debug::PrintTrait;


fn main() {
// Booleans (`bool`)

let is_morning = true;
if is_morning {
('Good morning!').print();

println!("Good morning!");
}

let // Finish the rest of this line like the example! Or make it be false!
if is_evening {
('Good evening!').print();

println!("Good evening!");
}
}
22 changes: 14 additions & 8 deletions exercises/primitive_types/primitive_types2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// I AM NOT DONE

use debug::PrintTrait;


fn main() {
// A short string is a string whose length is at most 31 characters, and therefore can fit into a single field element.
Expand All @@ -15,27 +15,33 @@ fn main() {
if is_alphabetic(
ref my_first_initial
) {
('Alphabetical!').print();

println!(" Alphabetical !");
} else if is_numeric(
ref my_first_initial
) {
('Numerical!').print();

println!(" Numerical !");
} else {
('Neither alphabetic nor numeric!').print();

println!(" Neither alphabetic nor numeric!");
}

let // Finish this line like the example! What's your favorite short string?
let // Finish this line like the example! What's your favorite short string?
// Try a letter, try a number, try a special character, try a short string!
if is_alphabetic(
ref your_character
) {
('Alphabetical!').print();

println!(" Alphabetical !");
} else if is_numeric(
ref your_character
) {
('Numerical!').print();

println!(" Numerical!");
} else {
('Neither alphabetic nor numeric!').print();

println!(" Neither alphabetic nor numeric!");
}
}

Expand Down
6 changes: 3 additions & 3 deletions exercises/primitive_types/primitive_types3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

// I AM NOT DONE

use debug::PrintTrait;


fn main() {
let cat = ('Furry McFurson', 3);
let // your pattern here = cat;
name.print();
age.print();
println!("name is {}", name);
println!("age is {}", age);
}
1 change: 1 addition & 0 deletions exercises/quizs/quizs1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ fn verify_test() {
assert(82 == price3, 'Incorrect price');
assert(130 == price4, 'Incorrect price');
}

1 change: 1 addition & 0 deletions exercises/starknet/basics/starknet4.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,4 @@ mod test {
contract0
}
}

2 changes: 1 addition & 1 deletion exercises/structs/structs3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ fn calculate_transport_fees() {

assert(package.get_fees(cents_per_gram) == 4500, 'Wrong fees');
}

1 change: 1 addition & 0 deletions exercises/traits/traits3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ fn test_traits3() {
assert(dog.make_noise() == 'woof', 'Wrong noise');
assert(dog.get_distance() == 1, 'Wrong distance');
}

7 changes: 4 additions & 3 deletions exercises/variables/variables1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// Make me compile!
// Execute `starklings hint variables1` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE
// I AM NOT DONE

use debug::PrintTrait;

fn main() {
x = 5;
x.print();
x = 5 ;
// x.print();
println!(" x is {}", x)
}
4 changes: 2 additions & 2 deletions exercises/variables/variables2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use debug::PrintTrait;
fn main() {
let x;
if x == 10 {
('x is ten!').print();
println!("x is ten! ");
} else {
('x is not ten!').print();
println!("x is not ten! ");
}
}
2 changes: 1 addition & 1 deletion exercises/variables/variables3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ use debug::PrintTrait;

fn main() {
let x: felt252;
x.print();
println!("x is {}", x);
}
4 changes: 2 additions & 2 deletions exercises/variables/variables4.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use debug::PrintTrait;

fn main() {
let x = 3;
x.print();
println!("x is {}", x);
x = 5; // don't change this line
x.print();
println!("x is now {}", x);
}
4 changes: 2 additions & 2 deletions exercises/variables/variables5.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use debug::PrintTrait;

fn main() {
let number = 1_u8; // don't change this line
number.print();
println!("number is {}", number);
number = 3; // don't rename this variable
number.print();
println!("number is {}", number);
}
4 changes: 2 additions & 2 deletions exercises/variables/variables6.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ use debug::PrintTrait;
const NUMBER = 3;
const SMALL_NUMBER = 3_u8;
fn main() {
NUMBER.print();
SMALL_NUMBER.print();
println!("NUMBER is {}", NUMBER);
println!("SMALL_NUMBER is {}", SMALL_NUMBER);
}

0 comments on commit 4afa59f

Please sign in to comment.