what are strings & operators?
string,a type of data used for storing and working with text
What is the purpose of variables in a code?
the purpose of a variable in a code is to keep track on
What does a Boolean expression evaluate?
True or False
what is a function?
A function is a named, self-contained block of reusable code designed to perform a specific task.
greeting = "Hello, world!"
print(greting)
print(greeting)because greeting is spelt wrong
when are strings & operators needed in coding?
strings and operators are needed when you need to represent texts and repeating and more.
Explain how a variable can work in a code?
a variable works as a container used to store and retrieve data in a computers memory.
What is the purpose of an else statement?
A fallback when an if statement is false.
what does a function do?
encapsulate a specific block of logic so it can be organized, reused, and managed.
health = 100
if health = 0:
print("Game Over")
Change the statement to use double equals: if health == 0:
what does a string do?
represent texts
var (clicks = 0)
onEvent(“addOneButton.”, “click.
Clicks = click + 1;
setProperty(“counter” “text”, clicks);
predict the output
the output is that each click is +1.
if (!isHungry || hasFood), what will
This check?
this will check if someone is not hungry OR has food to eat at lunch.
what parts do functions take place in coding?
functions are blocks of code designed to do specific tasks.
def calculate_average(test1, test2):
average = test1 + test2 / 2
return average
Group the addition before dividing: average = (test1 + test2) / 2
do you have to have strings & operators?
no
score = 12
bonus= 3
Score = score + bonus. What are the final values of score and
Bonus after the code runs? Explain how the variable change.
score :15
Bonus = 3
var temperature = 75;
if (temperature => 80) {
console.log("Hot");
} else if (temperature > 60) {
console.log("Warm");
} else {
console.log("Cold");}
What is the code telling us?
The code is telling us the weather is warm
How do functions go in order?
in sequential order
score = 150
if score <= 50:
print("Bronze Rank")
elif score <= 100:
print("Silver Rank")
elif score <= 150:
print("Gold Rank")
Order them from highest value to lowest, so the higher conditions don't get blocked by the broad score >= 50 condition:
how do springs & operators take part in coding?
to store, combine, and change text data
score1 = 72
Score 2 = 55
Score 3 = 83
Total = score1+score 2+score 3
Average = total /2
Find the mistakes
the mistakes are the average is calculated by dividing the total of 2, but there are three scores.
Result is only assigned when the average is atleast 60.
var score = 90;
if (score > 70) {
console.log("Passing");
} else {
console.log("Failing");}
Change the condition so that a score of exactly 70 also prints "Passing."
How do you know when your function is set?
when it satisfies a specific set of function, structural, and behavioral criteria.
player_gold = 100
def add_bonus(gold):
gold = gold + 50
add_bonus(player_gold)
print(player_gold)
Return the updated value from the function, and assign it back to the variable on the outside