Gdscript Problem Sets
Gdscript Problem Sets
OPERATORS
Defines two variables width and height.
Calculates and prints the area of a rectangle using these variables.
CONDITIONAL STATEMENT
Create a variable temperature, then write a conditional statement that prints:
"It's hot" if temperature is greater than 30. "It's warm" if it's between 20 and 30, and "It's cold"
if it's below 20.
Takes an integer number and checks if it's positive, negative, or zero.
Prints an appropriate message for each case.
WHILE LOOP
• Initialize
• Limit sa number
• Increment
FOR LOOP
1. Using for loop, print all odd numbers from 1 to 30.
2. Write a function is_even that takes an integer and returns true if it's even, and false if it's odd.
ARRAY
Create an array called numbers with the values [1, 2, 3, 4, 5].
1. Add the number 6 to the array.
2. Print the length of the array.
Given the item array ['HunterXHunter', 'Doraemon', 'Harry Potter', 'Fantastic Beasts'], write a
function that determines if a given value exists within it. The function should take two
parameters: the array and the search item.
If the search item exists in the array, print “Search item exists in the array”; otherwise, print
“Search item does not exist in the array”.
DICTIONARIES
1. Create a dictionary car with keys "make", "model", and "year".
Add a new key "color" with a value to the dictionary.
2. Given the dictionaries below, create a function that calculates and returns the average grade.
var grades = {
"Math": 90,
"Science": 85,
"English": 92,
"History": 88
}
Expected result:
The average grade is: 88
CLASSES AND OBJECTS
Create a class Animal with properties name and sound.
Add a method make_sound that prints the sound the animal makes.
Create an instance of Animal and call make_sound.
Defines a class Enemy with properties like type, health, and damage.
Adds a method attack that prints an attack message.
Creates multiple Enemy objects with different types and attacks.
GDSCRIPT ACTIIVTY NI SIR
1. Given a list of numbers, find the sum of all odd numbers.
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
2. Defines three variables: var1, var2, result. Set result to the product of var1 and var2. Print
the value of result.
4. Print the player's age (integer) in months. (1 year = 12 months) Result: "Your age in
months is [age_in_months]."
5. Using match statement, write a function day_of_week(day) that takes a number (1-7) and
prints the corresponding day of the week.
Example usage:
6. Find the Longest Word in a String. Write a function longest_word(s) that finds and returns
the longest word in a given strings.
7. Count Digits in a Number. Write a function count_digits(num) that returns the number of
digits in an integer.