Python Next Steps Homework 4 1
Python Next Steps Homework 4 1
def squareNumber():
num = int(input(“Enter a number: ”))
print(“Number squared =”, num * num)
(D)
print(“============”)
print(“Main Menu”)
print(“1. Add two numbers”)
print(“2. Square a number”)
print(“3. Quit”)
def quitMessage():
print(“Goodbye!”)
# MAIN METHOD
choice = 0
while choice != 3:
displayMenu()
choice = int(input(“Enter your choice: ”))
if choice == 1:
(A)
elif choice == 2:
(B)
elif choice == 3:
(C)
else:
print(“Error, invalid choice”)
(a) Write the piece of code that should appear at the point marked (A) [1]
addNumbers()
1
Homework 4: Introducing functions
Python Next Steps
(b) Write the piece of code that should appear at the point marked (B) [1]
squareNumber()
(c) Write the piece of code that should appear at the point marked (C) [1]
quitMessage()
(d) Write the piece of code that should appear at the point marked (D) [1]
displayMenu()
def shape(sides):
for counter in range(sides):
turtle.fd(100)
turtle.rt(360/sides)
# MAIN METHOD
square(100)
square(75)
square(50)
(a) Write one more line of code that would produce the following output [1]
square(25)
2
Homework 4: Introducing functions
Python Next Steps
(b) Write line of code that would produce a hexagon (six sided shape) [1]
shape(6)
(c) Write the main method that would produce the following shape [4]
Shape(3)
Shape(4)
Shape(5)
Shape(6)
[Total 12 marks]