Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding println #197

Merged
merged 4 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion corelib/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ version = 1

[[package]]
name = "core"
version = "2.4.1"
version = "2.5.3"
3 changes: 1 addition & 2 deletions exercises/dict/dict1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

// I AM NOT DONE


fn create_dictionary() -> Felt252Dict<u32> {
let mut dict: Felt252Dict<u32> = Default::default();
//TODO
//TODO

}

Expand Down
1 change: 0 additions & 1 deletion exercises/dict/dict2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// I AM NOT DONE



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

Expand Down
11 changes: 3 additions & 8 deletions exercises/dict/dict3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
// Make me compile and pass the test!
// Execute `starklings hint dict3` or use the `hint` watch subcommand for a hint.


// I AM NOT DONE


#[derive(Destruct)]
struct Team {
level: Felt252Dict<usize>,
players_count: usize
level: Felt252Dict<usize>,
players_count: usize
}

#[generate_trait]
Expand All @@ -41,11 +39,9 @@ impl TeamImpl of TeamTrait {
}



#[test]
#[available_gas(200000)]
fn test_add_player() {

let mut team = TeamTrait::new();
team.add_player('bob', 10);
team.add_player('alice', 20);
Expand All @@ -58,9 +54,8 @@ fn test_add_player() {
#[test]
#[available_gas(200000)]
fn test_level_up() {

let mut team = TeamTrait::new();
team.add_player('bobby',10);
team.add_player('bobby', 10);
team.level_up('bobby');

assert(team.level.get('bobby') == 11, 'Wrong level');
Expand Down
9 changes: 4 additions & 5 deletions exercises/enums/enums1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

// 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 +17,10 @@ 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___");
}
}
2 changes: 1 addition & 1 deletion exercises/enums/enums3.cairo
Original file line number Diff line number Diff line change
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);
}
3 changes: 1 addition & 2 deletions exercises/functions/functions3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// 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);
}
3 changes: 1 addition & 2 deletions exercises/functions/functions4.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
// 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
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;
shramee marked this conversation as resolved.
Show resolved Hide resolved
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;

shramee marked this conversation as resolved.
Show resolved Hide resolved
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;

shramee marked this conversation as resolved.
Show resolved Hide resolved

#[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();

shramee marked this conversation as resolved.
Show resolved Hide resolved
println!("grade is {}", course.unwrap());
display_grades(student, index + 1);

shramee marked this conversation as resolved.
Show resolved Hide resolved

shramee marked this conversation as resolved.
Show resolved Hide resolved
}


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

// I AM NOT DONE

use debug::PrintTrait;

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

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

shramee marked this conversation as resolved.
Show resolved Hide resolved
println!("Good morning!");
}

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

shramee marked this conversation as resolved.
Show resolved Hide resolved
println!("Good evening!");
}
}
16 changes: 7 additions & 9 deletions exercises/primitive_types/primitive_types2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

// 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.
// Short strings are actually felts, they are not a real string.
Expand All @@ -15,27 +13,27 @@ 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: 2 additions & 4 deletions exercises/primitive_types/primitive_types3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

// 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);
}
5 changes: 3 additions & 2 deletions exercises/variables/variables1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use debug::PrintTrait;

fn main() {
x = 5;
x.print();
x = 5 ;
// x.print();
shramee marked this conversation as resolved.
Show resolved Hide resolved
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);
}
Loading