NEW
Font size
Worksheetspython Pygame creation summer class
Total questions: 21
Worksheet time: 12mins
What is the extension on a Python file name?
.py
.xsl
.ppt
.docx
When creating a rectangle with the turtle, what angle is needed when turning?
120
180
45
90
To make the turtle move forward, which command is used?
turtle.penup()
turtle.forward()
turtle.left()
turtle.backward()
How do you pass arguments to a Python function?
Arguments are passed to a Python function by placing them inside the parentheses of the function call.
Arguments are passed to a Python function by telepathy
Arguments are passed to a Python function by writing them on a piece of paper and mailing it
Arguments are passed to a Python function by sending them via email
Explain the concept of 'nested loops' in Python.
Nested loops in Python involve one loop inside another loop, allowing for more complex iteration patterns.
Nested loops in Python involve loops that are not related to each other
Nested loops in Python involve loops that run sequentially
Nested loops in Python involve loops that cannot be used together
What is the purpose of the 'else' statement in Python conditional statements?
To repeat the 'if' condition
To execute a block of code when the condition in the 'if' statement is false.
To skip the 'if' condition
To define a new condition
What is the output of the following code snippet: 'x = 5 if x > 3: print('x is greater than 3')'?
x is less than 3
x is equal to 3
x is greater than 3
x is not defined
How do you add comments in Python code?
Use the '#' symbol to add comments in Python code.
Use the '/* */' symbols to add comments in Python code.
Use the '//' symbol to add comments in Java code.
Use the '//' symbol to add comments in Python code.
Why are comments important in programming?
Comments are used to hide malicious code within the program.
Comments are only for experienced programmers and not beginners.
Comments are unnecessary and slow down the code execution.
Comments provide clarity and context to the code.
How do you add comments in Python code?
Use the '#' symbol to add comments in Python code.
Use the '/* */' symbols to add comments in Python code.
Use the '//' symbol to add comments in Java code.
Use the '//' symbol to add comments in Python code.
What is the return statement used for in Python functions?
To exit the function and return a value back to the caller.
To import external libraries
To print a message to the console
To loop through a list of elements
How do you define a function in Python?
define function_name(parameters):
function_name(parameters):
function_name(parameters)
def function_name(parameters):
Explain the difference between 'for' and 'while' loops in Python.
The 'for' loop is used for executing a block of code repeatedly as long as a specified condition is true, while the 'while' loop is used for iterating over a sequence (like a list, tuple, string, etc.) or a range of numbers.
The 'for' loop is used for iterating over a sequence (like a list, tuple, string, etc.) or a range of numbers, while the 'while' loop is used for executing a block of code repeatedly as long as a specified condition is true.
What is the purpose of loops in Python?
Loops in Python are used for sorting data
The purpose of loops in Python is to iterate over sequences or execute a block of code repeatedly.
Loops in Python are designed to skip over code blocks
The purpose of loops in Python is to print statements only once
What are the different types of conditional statements in Python?
when
unless
otherwise
if, elif, else
What is a variable in Python?
A variable in Python is a mathematical operation.
A variable in Python is a type of function.
A variable in Python is a reserved memory location to store values.
A variable in Python is a type of snake.
Which pygame function is used to quit the python window ?
pygame.exit()
pygame.terminate()
pygame.quit()
pygame.close()
What is Pygame?
Pygame is a programming language.
Pygame is a software for editing images.
Pygame is a type of puzzle game.
Pygame is a set of Python modules used to create video games.
Draw a Rectangle
surface = pygame.display.set_mode((400,300))
pygame.draw.rect(surface, color, [30, 30, 60, 60])
pygame.draw.line(surface, color, [20, 50], [180, 50], 3)
pygame.draw.circle(surface, color, [300, 300], 200, 3)
How do I import the pygame library?
import pygame
pygame.init()
surface = pygame.display.set_mode((400,300))
pygame.display.flip()
What does the following code do?
if x >= 500: x = 0
x += 3
surface.fill((255, 255, 255))
circle = pygame.draw.circle(surface, (0, 0, 255), (x, y), 15)
pygame.display.update()
move the circle to right
create a surface
set initial position of the circle
check whether the circle pos. reached at the end
