Download Week 1 Written Assignment

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Name:__________
Honors Intro to Video Game Design
Assignment 1: Python Basics
The purpose of this assignment is to review the core data types, operators, and methods for
inputting and outputting data using Python. Attempt each question without actually running the
commands first, and then check your work afterward.
1)
Write one line of Python code that will print your name.
2) How do you enter a comment in a program?
3) Which commands below will print out the words 'Hello World' to the screen (circle all that do)?
a. print Hello World
b. print "Hello World"
c. print {“Hello World”}
d. print {'Hello World'}
e. print ['Hello World']
f. print 'Hello World'
4) What will be output when the code below is run?
a =1
b =3
print("a+b")
5) What do the following lines of code output?
a) print(2 / 3)
b) print(2 // 3)
6) Why are parts a) and b) from question 5 different?
7)
Why will the code below result in an error?
A = 22
print(a)
1
8) All of the variable names below can be used. But which ONE of these is the better variable name to
use?
a
A
Area
AREA
area
area_of_rectangle
Area_Of_Rectangle
9) Which of these variables names are not allowed in Python? More than one might be wrong. Test
them if you aren't sure!
apple
Apple
APPLE
Apple2
1Apple
account number
account_number
account.number
accountNumber
account#
pi
PI
fred
Fred
GreatBigVariable
greatBigVariable
great_big_variable
great.big.variable
2x
x2x
total%
#left
10) Why does this code not work?
print(a)
a = 45
2
11) Explain the mistake in the following code:
x = 4
y = 5
a = 3(x + y)
print a
12) The code below is supposed to calculate the average of 3, 4, and 5, but its result is incorrect. What
is the error, and how can it be fixed?
print(3 + 4 + 5 / 3)
13) What does the following program print out?
x = 3
x + 1
print(x)
14) The following line of code will not run. Correct the mistake that is causing the error.
player_name = raw_input("Enter your name: )"
15) Suppose you want to get the age of a user. You write a line of code that you think will display the
prompt “Enter your age”, convert the input to an integer, and store that input in the variable value.
Why does the code below not work, and how can it be fixed?
value = int(raw_input(print("Enter your age")))
3
16) Consider the code segment below:
player_health = 100
player_loot = 40000
enemy_damage = 4.2
# Calculate player health after enemy attack
player_health = player_health – enemy_damage
print player_health
a) What would the statement print type(player_loot) output to the console?
b) What would the statement print type(enemy_damage) output to the console?
17) Assume you have values in the variables x and y. Which statement(s) would result in x having the
sum of the current values of x and y (select all that work)?
a. x += x + y
b. y += x
c. x = x + y
d. x = y + x
18) Python file names traditionally end in what characters after a period? Don't include the period.
19) Why will an error occur when the code below is run?
x = raw_input("Enter a number:")
x = x/2
print(x)
20) What is output when the command print("Have a "great" day!")
4