Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
Level 20, 21 and 22 implemented (hedyorg#442)
Browse files Browse the repository at this point in the history
* Level 20, 21 and 22 implemented

Levels were the same as before but at a different position now
  • Loading branch information
LauraTSD authored May 27, 2021
1 parent 9e7a2e7 commit acf020d
Show file tree
Hide file tree
Showing 14 changed files with 2,751 additions and 8 deletions.
5 changes: 4 additions & 1 deletion coursedata/course/hedy/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ course:
- level: "16"
- level: "17"
- level: "18"
- level: "19"
- level: "19"
- level: "20"
- level: "21"
- level: "22"
5 changes: 4 additions & 1 deletion coursedata/course/hedy/nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ course:
- level: "16"
- level: "17"
- level: "18"
- level: "19"
- level: "19"
- level: "20"
- level: "21"
- level: "22"
83 changes: 82 additions & 1 deletion coursedata/level-defaults/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,85 @@
fruit is ['apple', 'banana', 'cherry']
print('length of list is ' length(fruit))
for i in range(1, length(fruit)):
print(fruit[i])
print(fruit[i])
20:
start_code: |-
print('What is 5+3?')
answer = 5+3
print('answer is now:')
print(answer)
if answer == 8:
print('That is correct!')
else:
print('Oh no, that is wrong!')
intro_text: "Now we are going to change is into `=` and `==`. We use `=` if we want to assign a value to a variable. If you want to assign 8 to the variable called anser, we do answer = 8. `==` we use when we want to see if two things are the same."
commands:
- name: "Compare"
explanation: "If we want to compare, we use ==. 5+3 == 8 checks if 5+3 equals 8"
example: "For example: 5+3 == 8"
demo_code: |-
if 5+3 == 8:
print('5+3 is indeed 8')
else:
print('This will not be printed because 5+3 is 8!')
- name: "Assign Value"
explanation: "If we want to say that a variable called answer is 8, we do answer = 8."
example: "For example: answer = 8"
demo_code: |-
print('What is 5+3?')
answer = 5+3
print('answer is now:')
print(answer)
- name: "Compare and assign value"
explanation: "If we are going to compare two values, we use `==`. If we are going to assign a variable, we use `=`. "
example: "For example: 5+3 == 8, answer = 8"
demo_code: |-
print('What is 5+3?')
answer = 5+3
print('answer is now:')
print(answer)
if answer == 8:
print('That is correct!')
else:
print('No, that is wrong!')
21:
start_code: |-
country = input('Where do you live?')
if land != Netherlands:
print('Cool!')
else:
print('I am also from the Netherlands!')
intro_text: "We are going to learn a new item, the `!=` . The ! means not and the = means equal so != means not equal. For example 5 != 4."
commands:
- name: "Not equal"
explanation: "If we are checking if two things are not equal, we use `!=`"
example: "For example: 5+3 != 9"
demo_code: |-
number = input('You are not allowed to say 5, what is a cool number?')
if getal != 5:
print('Good job!')
else:
print('You were not allowed to say 5!')
22:
start_code: |-
age = input('I am 12 years old, how old are you?')
if age <= 11:
print('You are younger than I am!')
elif age >= 13:
print('You are older than I am!')
intro_text: "We are going to combine < and = now. If we want to see if something is smaller or equal than the second number, we use `<=`. We can also check if something is bigger or equal than the second number with `>=`."
commands:
- name: "Smaller equal"
explanation: "`<=` checks if the number on the left of the `<=` is smaller or equal than the one on the right. So 5 < 5 is not true because 5 is not smaller than 5 but 5 <= 5 is true because 5 is smaller or equal to 5. 6 <= 5 is not true."
example: "For example: age <= 12"
demo_code: |-
age = input('I am 13 years old, how old are you?')
if age <= 12:
print('You are younger than I am!')
- name: "Larger equal"
explanation: "`>=` checks if the number on the left of the `>=` is bigger or equal than the one on the right. So 5 > 5 is not true because 5 is not bigger than 5 but 5 >= 5 is true because 5 is smaller or equal to 5. 4 >= 5 is not true."
example: "For example: age >= 12"
demo_code: |-
age = input('I am 11 years old, how old are you?')
if age >= 12:
print('You are older than I am!')
83 changes: 82 additions & 1 deletion coursedata/level-defaults/nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,85 @@
fruit is ['appel', 'banaan', 'kers']
print('lengte van de lijst is ' length(fruit))
for i in range(1, length(fruit)):
print(fruit[i])
print(fruit[i])
20:
start_code: |-
print('Hoeveel is 5+3?')
antwoord = 5+3
print('antwoord is nu:')
print(antwoord)
if antwoord == 8:
print('Dat is goed!')
else:
print('Helaas dat is fout!')
intro_text: "Nu veranderen we is in `=` en `==`. Je gebruikt `=` als je iets een getal wilt maken. Als je bijvoorbeeld antwoord 8 wilt maken zeg je antwoord = 8. `==` gebruik je om te kijken of twee dingen hetzelfde zijn."
commands:
- name: "Vergelijken"
explanation: "Als we gaan vergelijken gebruiken we dus ==. 5+3 == 8 kijkt dus of 5+3 gelijk is aan 8"
example: "Bijvoorbeeld: 5+3 == 8"
demo_code: |-
if 5+3 == 8:
print('5+3 is inderdaad 8')
else:
print('Dit wordt niet geprint want 5+3 is 8!')
- name: "Waarde geven"
explanation: "Als we willen zeggen dat een variabele genaamd antwoord 8 is, dan doen we antwoord = 8."
example: "Bijvoorbeeld: antwoord = 8"
demo_code: |-
print('Hoeveel is 5+3?')
antwoord = 5+3
print('antwoord is nu:')
print(antwoord)
- name: "Vergelijken en waarde geven"
explanation: "Als we gaan vergelijken gebruiken we dus `==`. Als we een waarde geven dan gebruiken we `=`. "
example: "Bijvoorbeeld: antwoord == 8, antwoord = 8"
demo_code: |-
print('Hoeveel is 5+3?')
antwoord = 5+3
print('antwoord is nu:')
print(antwoord)
if antwoord == 8:
print('Dat is goed!')
else:
print('Helaas dat is fout!')
21:
start_code: |-
land = input('In welk land woon jij?')
if land != Nederland:
print('Cool!')
else:
print('Ik kom ook uit Nederland!')
intro_text: "We gaan een nieuw teken leren, de `!=` . De ! betekent niet en de = betekent gelijk dus != is niet gelijk. Als voorbeeldje is 5 != 4."
commands:
- name: "Niet gelijk"
explanation: "Als we gaan kijken of dingen anders zijn, gebruiken we dus `!=`"
example: "Bijvoorbeeld: 5+3 != 9"
demo_code: |-
getal = input('Je mag geen 5 zeggen, wat is een leuk getal?')
if getal != 5:
print('Goed zo!')
else:
print('Fout! Je mocht geen 5 zeggen')
22:
start_code: |-
leeftijd = input('Ik ben 12 jaar, hoe oud ben jij?')
if leeftijd <= 11:
print('Dan ben je jonger dan ik!')
elif leeftijd >= 13:
print('Dan ben je ouder dan ik!')
intro_text: "Nu gaan we < en = combineren. Als we willen kijken of iets kleiner of gelijk aan het tweede getal is dan gebruiken we `<=`. Hetzelfde kunnen we doen met `>=`"
commands:
- name: "Kleiner gelijk"
explanation: "De `<=` kijkt dus of het eerste getal kleiner of gelijk is aan het tweede getal. Dus 5 < 5 is niet waar want 5 is niet kleiner dan 5 maar 5 <= 5 is wel waar want 5 is gelijk aan 5. 6 <= 5 is dus niet waar."
example: "Bijvoorbeeld: leeftijd <= 12"
demo_code: |-
leeftijd = input('Ik ben 13 jaar, hoe oud ben jij?')
if leeftijd <= 12:
print('Dan ben je jonger dan ik!')
- name: "Groter gelijk"
explanation: "De `>=` kijkt dus of het eerste getal groter of gelijk is aan het tweede getal. Dus 5 > 5 is niet waar want 5 is niet groter dan 5 maar 5 >= 5 is wel waar want 5 is gelijk aan 5. 4 >= 5 is dus niet waar."
example: "Bijvoorbeeld: leeftijd >= 12"
demo_code: |-
leeftijd = input('Ik ben 11 jaar, hoe oud ben jij?')
if leeftijd >= 12:
print('Dan ben je ouder dan ik!')
2 changes: 1 addition & 1 deletion grammars/level18.lark
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
start: program
program: _EOL* command (" ")* (_EOL+ command (" ")*)* _EOL* //lines may end on spaces and might be separated by many newlines
?command: print
| ifs elifs? elses?
| ifs (elifs)* elses?
| input
| for_loop
| while_loop
Expand Down
2 changes: 1 addition & 1 deletion grammars/level19.lark
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
start: program
program: _EOL* command (" ")* (_EOL+ command (" ")*)* _EOL* //lines may end on spaces and might be separated by many newlines
?command: print
| ifs elifs? elses?
| ifs (elifs)* elses?
| input
| for_loop
| while_loop
Expand Down
98 changes: 98 additions & 0 deletions grammars/level20.lark
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// trying to simply copy level 6 allowing for spaces
// the idea here is:
// allows for almost the same grammar as 6, easy for us
// gives better error messages out of the box
// we check indents in code, we can give better indent errors

start: program
program: _EOL* command (" ")* (_EOL+ command (" ")*)* _EOL* //lines may end on spaces and might be separated by many newlines
?command: print
| ifs (elifs)* elses?
| input
| for_loop
| while_loop
| assign_list
| list_access_var
| change_list_item
| comment
| assign //placing it here means print is will print 'is' and print is Felienne will print 'is Felienne'

//we had to drop invalid, I think because of the if-ifelse, but for now it is pretty ok!!

_EOL: "\r"?"\n"


print : "print(" (quoted_text | list_access | var | sum | length) (" " (quoted_text | list_access | var | sum | length))* ")"
input : var " = input(" (quoted_text | list_access | var | sum | length) (" " (quoted_text | list_access | var | sum | length))* ")"
assign_list: var " = [" quoted_text ((", "|",") quoted_text)+ "]"

//TODO: sum needs to be expression here too (like in 7 and up)

assign : var " = " length | var " = " sum | var " = " textwithoutspaces | list_access " = " sum | list_access " = " textwithoutspaces
invalid: textwithoutspaces " " textwithspaces


// new commands for level 4
elses : _EOL (" ")* "else"":" _EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block"
ifs: "if " (condition|andcondition|orcondition) ":" _EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block" //'if' cannot be used in Python, hence the name of the rule is 'ifs'
elifs: _EOL (" ")* "elif " (condition|andcondition|orcondition) ":"_EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block"


condition: (equality_check|in_list_check|smaller|bigger)
list_access_var : var " = " var "[" (index | random | var) "]"
equality_check: (length | textwithoutspaces | list_access | sum) " == " (length | textwithoutspaces | list_access | sum)
in_list_check: textwithoutspaces " in " var

//new for level 6
?sum: product
| sum " "* "+" " "* product -> addition
| sum " "* "-" " "* product -> substraction

?product: atom
| product " "* "*" " "* atom -> multiplication
| product " "* "/" " "* atom -> division

?atom: NUMBER | var | NAME | list_access //TODO: means we cannot assign strings with spaces? would we want that?

//new for level 8
for_loop: "for " (NAME | var) " in " "range(" (NUMBER | var | length)(", "|",") (NUMBER | var | length) "):" _EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block"

//new for level 12, assignment of list[i]
change_list_item : var "[" (index | var) "] = " (var | textwithoutspaces)

//new for level 14
andcondition: (equality_check|in_list_check) (" and " condition)*
orcondition: (equality_check|in_list_check) (" or " condition)*

//new for level 15
comment: "#" (textwithspaces)*

//new for level 16
smaller: (textwithoutspaces | list_access | length) " < " (textwithoutspaces | list_access | length)
bigger: (textwithoutspaces | list_access | length) " > " (textwithoutspaces | list_access | length)

//new for level 17
while_loop: "while " (condition|andcondition|orcondition) ":" _EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block"

//new for level 19
length: "length(" var ")"

var: NAME -> var
list_access : var "[" (index | random | var | length) "]"
index : NUMBER
random : "random"

textwithspaces: /([^\n,]+)/ -> text //anything can be parsed except for a newline and a comma for list separators
textwithoutspaces: /([^\n, :*+-\/]+)/ -> text //anything can be parsed except for spaces (plus: a newline and a comma for list separators)
//plus in level 6, calculation elements
//plus in level 8, colon

quoted_text_no_escape: /'([^']*)'/ -> text //simply all between quotes should this be used at earlier levels?
quoted_text: /'((?:[^\\']|\\.)*)'/ -> text //text can be between single quotes, but quotes may be escaped with \

%import common.LETTER // imports from terminal library
%import common.DIGIT // imports from terminal library
%import common.WS_INLINE // imports from terminal library
%import common.NEWLINE // imports from terminal library
%import common.SIGNED_INT -> NUMBER
%import common.CNAME -> NAME
Loading

0 comments on commit acf020d

Please sign in to comment.