0% found this document useful (0 votes)
19 views

Gdscript Problem Sets

Uploaded by

marcopomoy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Gdscript Problem Sets

Uploaded by

marcopomoy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

VARIABLES AND DATA TYPES

Defines three variables: x, y, and z.


Assigns values to x and y.
Sets z to the sum of x and y.
Prints the value of z.

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. 2. Given a list of numbers, find the product of all even numbers.


var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Expected result:
The product is: 46080
MATCH STATEMENT
Defines a variable command with values like "start", "stop", or "pause".
Uses a match statement to print appropriate actions based on the value of command.
FUNCTIONS
1. Write a function called add_numbers that takes two arguments and returns their sum.

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.

3. Find Palindromic Numbers in an Array. Write a function find_palindromes(arr) that returns


an array of palindromic numbers from the given array.

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.

8. Generate Random Number within a Range. Create a function random_in_range(min,


max) that returns a random integer between min and max, inclusive.

You might also like