60 lines
1.0 KiB
Python
60 lines
1.0 KiB
Python
# %%
|
|
#Task 1 - Functions
|
|
#A
|
|
def Hello():
|
|
print("Hello world")
|
|
Hello()
|
|
|
|
# %%
|
|
# B
|
|
def HelloTo(name):
|
|
print("Hello "+name+"!")
|
|
HelloTo("Nick")
|
|
|
|
# %%
|
|
# C
|
|
def Distance(x1,y1,x2,y2):
|
|
return ((x2-x1)**2+(y2-y1)**2)**1/2
|
|
Distance(0,0,1,1)
|
|
|
|
# %%
|
|
# Task 2
|
|
# A
|
|
|
|
def GetDirection():
|
|
valid_options = ['Q','N','S','E','W']
|
|
stop = 1
|
|
while 1:
|
|
direction = input("Please enter Q,N,E,S,W: ")
|
|
for option in valid_options:
|
|
if option == direction:
|
|
return direction
|
|
|
|
# %%
|
|
# B
|
|
|
|
def ParseInput(direction):
|
|
new_direction = ""
|
|
if direction == "N":
|
|
new_direction = "north"
|
|
if direction == "S":
|
|
new_direction = "south"
|
|
if direction == "E":
|
|
new_direction = "east"
|
|
if direction == "W":
|
|
new_direction = "west"
|
|
print("The players moves "+new_direction)
|
|
|
|
# %%
|
|
# C
|
|
|
|
def GameLoop():
|
|
user_input=""
|
|
while user_input != "Q":
|
|
user_input = GetDirection()
|
|
if user_input != "Q":
|
|
ParseInput(user_input)
|
|
GameLoop()
|
|
|
|
|