a long, long time ago in a galaxy far, far away
# %load MSBA_Exercise_1_solution_v2
'''
MSBA Programming Boot Camp
In-class Exercise 1
'''
#########################
#Q1. Simple Arithmetic #
#########################
# Note that in many cases, there's no need to use print() to display.
# But for illustration, it's clearer to use print().
print(50+10)
print(100-20)
print(2*4)
print(4/2)
print(2**3)
print(10%2)
print(11%2)
print(11/3)
print(11//3)
#########################
#Q2.Variable Assignment #
#########################
# Assign x and y to the values 5 and 10 respectively.
# Add them together and print the result
x = 5
y = 10
# Write your answer here
print(x+y)
result = x + y
print(result)
# Replace this name with yours
first_name = 'master '
last_name = 'yeoda'
# Print your name
# Write your answer here hint: be careful with whitespace
print(first_name + last_name)
#######################################
#Q3.Boolean and If-statement practice #
#######################################
# Write an if-then statement to determine if Chewie is hungry.
dog = 'Chewie'
is_hungry = False
# Write your answer here
if is_hungry == True:
print("{} is hungry!".format(dog))
else:
print("{} is not hungry :)".format(dog))
# Now try it with 3 conditions.
# If Link's level is < 10, he's not ready for
# the boss. If his level is 10, he needs a new sword.
# If his level is > 10, he's ready for the boss.
# Write your answer here
character_name = "Link"
level = 10
# This is probably a more straightforward if-then-else.
if level < 10:
print(character_name + " is " + "not ready for the boss")
elif level == 10:
print(character_name + " should " + "buy a new sword")
else:
print(character_name + " is " + "ready")
############################
#Q4.Data Structure -- List #
############################
## creating a list
py_list = [1,2,3]
## adding something to the list
py_list.append(10)
## Accessing data inside of the list
# Print the list
# Write your answer here
print(py_list)
# Access the first element. note that python counts from 0.
# Write your answer here
print(py_list[0])
# Access the 3rd element.
# Write your amswer here
print(py_list[2])
# Remove the the element "1".
# Remove some data from the list
py_list.remove(1)
# check the list again. Print it.
# Write your answer here
print(py_list)
## Let's create another list
## Remember that we declared and assigned values to variables
#print(x, y, character_name, level, first_name, last_name)
## We can use variables because we have assgined values earlier
## Let's put these values to a list
# check the data structure. Use type()
var_list = [x, y, character_name, level, first_name, last_name]
var_list
type(var_list)
00