0% found this document useful (0 votes)
3 views4 pages

Python Game Dev Assignment

Uploaded by

neeruchahar130
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Python Game Dev Assignment

Uploaded by

neeruchahar130
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Game Developer Assignment

Welcome, Developer! Test your Python logic, syntax, and problem-solving skills across these
epic gaming scenarios.

Part 1: Core Mechanics (Multiple Choice)

1. How do you correctly create a variable to store the player's starting lives (3) in Python?

A. lives = 3
B. 3 = lives
C. lives == 3
D. var lives: 3

2. You need to keep track of whether the final boss is defeated or not. Which datatype is the
best choice for the variable 'boss_defeated'?

A. Integer
B. String
C. Boolean
D. Float

3. Your game needs to welcome the player by combining "Welcome, " with their chosen
name. If 'name = "Zelda"', which code correctly makes the string "Welcome, Zelda"?

A. "Welcome, " * name


B. "Welcome, " - name
C. "Welcome, " & name
D. "Welcome, " + name

4. Your character finds a magic potion that doubles their current strength! If 'strength = 10',
which operator should you use to update their strength to 20?

A. strength = strength + 2
B. strength = strength * 2
C. strength = strength ** 2
D. strength = strength / 2
5. A merchant sells a magic shield for 100 gold. Which 'if' statement correctly checks if the
player has enough gold to buy it?

A. if gold < 100:


B. if gold = 100:
C. if gold >= 100:
D. if gold != 100:

6. You want to spawn exactly 5 zombies in your game level. Which 'for' loop will run exactly
5 times?

A. for i in range(1, 5):


B. for i in range(6):
C. for zombie in 5:
D. for i in range(5):

7. Which loop is the best choice to keep a boss battle going as long as the boss's health is
greater than zero?

A. for health in range(0):


B. while health > 0:
C. while health < 0:
D. for health > 0:

8. You want to create a reusable block of code that heals the player. How do you correctly
start defining this function in Python?

A. function heal_player():
B. create heal_player():
C. def heal_player():
D. def heal_player:

9. You want to show the player their level on the screen: "Level: " + level. If the variable
'level' holds an integer, what must you do to prevent Python from crashing?

A. Convert the string to an integer using int("Level: ")


B. Multiply the string by the integer
C. Nothing, Python does it automatically
D. Convert the integer to a string using str(level)
10. In a loop checking 10 treasure chests, you find a trap! Which keyword would you use to
immediately exit the entire loop so you don't open any more chests?

A. continue
B. stop
C. break
D. pass

Part 2: Epic Quests (Case Studies)

Read the scenario for each game mechanic and write out the Python code needed to solve the problem.

Case Study 1: The Overheal Glitch

Concepts: Variables, Datatypes, Operators, If/Else


Player Current HP: 85 | Max HP: 100 | Potion Heal Amount: 50

The Task:

Your player drinks a massive healing potion. However, in your game, a player's health cannot go
above their Max HP. Write a Python script that adds the potion amount to the player's current HP.
Then, use an if/else statement to check if their HP went over 100. If it did, set their HP exactly
back to 100 and print "Max health reached!". Otherwise, print their new HP.

Case Study 2: The Grumpy Guard Dialogue

Concepts: Strings, String Methods, If/Elif/Else


Player Input: " Let me pass " (Notice the extra spaces and weird
capitalization)

The Task:

A guard is blocking the bridge. The player types a response to the guard, but players often type
messily. Write a script that takes the player's input string, removes the blank spaces from the
beginning and end, and converts it entirely to lowercase. Then, write an if/elif/else block:
- If they say "let me pass", the guard says "Only if you have the password."
- If they say "sword", the guard says "Put that away!"
- For anything else, the guard says "I don't understand you."
Case Study 3: The Enemy Wave Multiplier

Concepts: For Loops, Operators, Variables


Total Waves: 5

The Task:

You are designing a survival game where enemies spawn in waves. Write a `for` loop that
simulates 5 waves (Wave 1 to Wave 5). In Wave 1, 3 enemies spawn. Every wave after that, the
number of enemies is multiplied by 2. Print out the wave number and the number of enemies
spawning for all 5 waves.

Case Study 4: The Poison Swamp Survival

Concepts: While Loops, Variables, Operators


Player HP: 30 | Poison Damage: 7 per step

The Task:

The player is stuck in a poison swamp! Every step they take lowers their HP by 7. Write a `while`
loop that keeps running as long as the player's HP is greater than 0. Inside the loop, subtract 7
from their HP and print "Took 7 poison damage. HP is now [HP]". When the loop finishes, print
"The player has fainted."

Case Study 5: The Critical Hit Calculator

Concepts: Functions, If/Else, Operators, Datatypes


Inputs needed: Base Damage (integer), Is Critical (boolean)

The Task:

Create a custom Python function named calculate_damage that takes two parameters:
base_damage and is_critical. Inside the function, write logic that checks if is_critical is
True. If it is, multiply the base damage by 2.5 and return the new amount. If it is False, just return
the normal base damage. Finally, call your function and print the result for a base damage of 20
that IS a critical hit.

You might also like