Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
148 views

Python Skills Worksheet 3a Functions

This document provides examples of functions to control a household robot. It includes functions for vacuuming, setting the table, and playing tic-tac-toe. For exercise 1, it shows functions for vacuuming and setting the table, with example calls to those functions. For exercise 2, it lists function calls that could be used to play a game of tic-tac-toe and instructs the user to reorder them to play a game without other inputs. For exercise 3, it instructs the user to uncomment function calls in a provided tic-tac-toe program to test it under different win/loss/draw conditions.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views

Python Skills Worksheet 3a Functions

This document provides examples of functions to control a household robot. It includes functions for vacuuming, setting the table, and playing tic-tac-toe. For exercise 1, it shows functions for vacuuming and setting the table, with example calls to those functions. For exercise 2, it lists function calls that could be used to play a game of tic-tac-toe and instructs the user to reorder them to play a game without other inputs. For exercise 3, it instructs the user to uncomment function calls in a provided tic-tac-toe program to test it under different win/loss/draw conditions.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Worksheet 3a

Practical programming skills in Python

Worksheet 3a Functions
1. Create a series of functions for a robot to do your household chores

e.g. Washing up, vacuuming, making the bed

Add some function calls at the end of the program so that the robot will do them

Your answer should look something like this:

print ("Exercise 1")

print ("\n")

def vacuum():

print("Get the vacuum cleaner")

print("Turn on the vacuum cleaner")

print("Vacuum around the house")

print("Turn off the vacuum cleaner")

print("Place the vacuum cleaner inside the wardrobe")

def setTheTable():

print("Place the tablecloth")

print("Place cups")

print("Place the knives, forks and spoons")

print("Place the plates")

print("Place the napkins")

vacuum()

print ("\n")

setTheTable()

1
Worksheet 3a
Practical programming skills in Python

2. Tic - Tac - Toe

Use the following function calls to put together a complete game of Tic Tac Toe.

Rewrite them and repeat them (on paper) in an order that would allow you to play the
game. You can do this as a flowchart instead if you prefer.

Test the game by playing against someone else (you play as the player, they play as the
computer). Neither one is allowed to do anything that isn’t in the program you’ve designed.

drawGrid()
playerChooses()
checkIfSomeoneWon()
computerChooses()
checkIfSomeoneWon()

3. Tic - Tac - Toe

Download the Tic Tac Toe program (L3 WS3a Ex2 tic_tac_toe.py).

The subroutines are already completed for you, all you need to do is uncomment the calls
at the bottom of the program. You can copy each one as many times as you need to.

Test the program thoroughly – make sure it works if you win, lose or draw (it might take a
few goes to lose successfully!).

You might also like