SlideShare uma empresa Scribd logo
1 de 19
Core Principles
of Programming
with python
Week 3
Main Menu
A main menu is what is displayed at the
start of any program.
It should be kept in a function and
mainly includes an IF statement.
An example of a main menu using last weeks
code is:
Remembering to use .upper() for validation.
Activity
Using what you have just learnt,
Help
• Remember to use IF and ELIF
statements for each option as
the ELSE statement should be
used if the user enters anything
that isn’t an option.
• Also remember to use .upper()
as a basic form of validation.
Create a main menu for your code from last week.
First Project Layout To achieve this, we will be using the
import command to import into our
project, our first Python library.
The layout of the project will be:
- Main Menu
- Rock Paper Scissors against AI
- Tic Tac Toe against either AI or another player
Setup Activity
Before we get ahead of ourselves:
Further activity
Create a new folder called “Python Game Project”.
Create a new file called “main.py”
Create a function for the main menu with three options:
• Rock Paper Scissors
• Tic Tac Toe
• Exit
Create two functions:
• rockpaperscissors()
• tictactoe()
The main menu should call these functions respectively
Try and place the main menu in a while loop for
validation, that is only exited if the user inputs the
exit choice of the menu.
The main menu should look like this
Console output:
The Further activity main menu should look like this
Console output:
Random Library
A library is a collection of prewritten python
functions that we can use.
The one we will be using today is the “random”
library.
Standard practice is to place all your imports at the
top of the code.
Random.randint() is the command to pick a number
between the first integer and the second integer
(including both of them).
An example of the random and random.randint()
code is:
This code will print a random number of either 1,
2, or 3.
Rock Paper Scissors
Now is the time to flex your skills.
I will let you guys crack on but here is how I would
lay out the program:
• Import random
• Ask the user what they would like to pick
• Print what the computer decided on (1 = Rock, 2
= Paper, 3 = Scissors)
• Compare the two values
• Print if it is a win, lose or draw
• Ask the user to play again (optional)
• Return to main menu
Help
• Compare the users input with
numbers to make your life easier
• Remember “AND” for comparing
values in the IF statement.
• There will be a lot of IF
statements in this program so do
not worry if you have a lot.
• Also remember to use .upper()
as a basic form of validation.
Rock Paper Scissors
For more help here is the comparison code:
• Import random
• Ask the user what they would like to pick
• compChoice = Randint(1,3)
• Convert that to a words
• Print what the computer decided on (1 = Rock, 2
= Paper, 3 = Scissors)
• Compare the two values
• Print if it is a win, lose or draw
• Ask the user to play again (optional)
• Return to main menu
Help
Rock Paper Scissors Here is the full code:
Arrays
An array is a special variable that can be used to
store multiple values in one single variable.
To access a value in the array you would write
the arrays name and then the index of the value
you want in square brackets.
An example of an array is:
0 1 2 3
This would print the word “Is”
as the first value of the array is
called 0.
Tic Tac Toe
Now this is the ultimate challenge.
How I would go about it:
• Create a Board Array to store what spots are empty.
• PrintTable() Function
• Pick which player one, will be (X or O)
• Compare the win conditions of the slots
• When the board is filled, print it was a draw.
• Ask the user to play again (optional)
• Return to main menu
Help
• Print the table with “–” and “|”
• Use board[x] to pick a certain
value in the list.
• Having the win conditions in a
test function will help you
repeatedly check if anyone has
won.
• Also remember to use numbers
for the nine slots.
Tic Tac Toe
Here is some code for printing the
board:
How I would go about it:
• Create a Board Array to store what spots are empty.
• PrintTable() Function
• Pick what player one will be (X or O)
• Compare the win conditions of the slots
• When the board is filled, print it was a draw.
• Ask the user to play again (optional)
• Return to main menu
Help
Tic Tac Toe
Here is some code for validation:
Help
The win conditions for Tic-Tac-Toe:
Tic Tac Toe
Here is the code for entering a position:
Tic Tac Toe
Here is the code for:
• Checking if anyone has won
• Swapping between players
• And asking the user if they want to play again.
Home Activity
Combining what you have learnt today,
Try and make a computer opponent version of Tic-Tac-Toe
using randint() to pick their turns.
End of week Three
And have a good Christmas

Mais conteúdo relacionado

Semelhante a Week3.pptx

Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxswarna627082
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 
Core Concept_Python.pptx
Core Concept_Python.pptxCore Concept_Python.pptx
Core Concept_Python.pptxAshwini Raut
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfMichpice
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3aRuth Marvin
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Fariz Darari
 
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptxLecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptxAbdulQadeerBilal
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdfgmadhu8
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPTShivam Gupta
 
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxWeek 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxmelbruce90096
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxadihartanto7
 

Semelhante a Week3.pptx (20)

Basic use of Python
Basic use of PythonBasic use of Python
Basic use of Python
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
Core Concept_Python.pptx
Core Concept_Python.pptxCore Concept_Python.pptx
Core Concept_Python.pptx
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1
 
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptxLecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
 
Week 1.pptx
Week 1.pptxWeek 1.pptx
Week 1.pptx
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
 
Python basics
Python basicsPython basics
Python basics
 
Python
PythonPython
Python
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxWeek 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
 
Baabtra.com little coder chapter - 2
Baabtra.com little coder   chapter - 2Baabtra.com little coder   chapter - 2
Baabtra.com little coder chapter - 2
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
 

Último

Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4wistariecz
 
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证khuurq8kz
 
codes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptxcodes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptx17duffyc
 
HUMA Final Presentation About Chicano Culture
HUMA Final Presentation About Chicano CultureHUMA Final Presentation About Chicano Culture
HUMA Final Presentation About Chicano Culturekarinamercado2462
 
THE ARTS OF THE PHILIPPINE BALLET PRESN
THE ARTS OF  THE PHILIPPINE BALLET PRESNTHE ARTS OF  THE PHILIPPINE BALLET PRESN
THE ARTS OF THE PHILIPPINE BALLET PRESNAlvinFerdinandAceCas
 
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...Sheetaleventcompany
 
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)River / Thao Phan
 
WhatsApp-(# 9711106444 #)Call Girl in Noida Sector 80 Noida (Escorts) Delhi
WhatsApp-(# 9711106444 #)Call Girl in Noida Sector 80 Noida (Escorts) DelhiWhatsApp-(# 9711106444 #)Call Girl in Noida Sector 80 Noida (Escorts) Delhi
WhatsApp-(# 9711106444 #)Call Girl in Noida Sector 80 Noida (Escorts) Delhidelhimunirka15
 
Russian Call Girls Pilibhit Just Call 👉👉 📞 8617370543 Top Class Call Girl Ser...
Russian Call Girls Pilibhit Just Call 👉👉 📞 8617370543 Top Class Call Girl Ser...Russian Call Girls Pilibhit Just Call 👉👉 📞 8617370543 Top Class Call Girl Ser...
Russian Call Girls Pilibhit Just Call 👉👉 📞 8617370543 Top Class Call Girl Ser...Nitya salvi
 
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶delhimunirka15
 
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155SaketCallGirlsCallUs
 
Nehru Nagar, Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genui...
Nehru Nagar, Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genui...Nehru Nagar, Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genui...
Nehru Nagar, Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genui...delhimunirka15
 
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...Nitya salvi
 
Call Girls In Firozabad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Firozabad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Firozabad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Firozabad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Nitya salvi
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607dollysharma2066
 
Digital C-Type Printing: Revolutionizing The Future Of Photographic Prints
Digital C-Type Printing: Revolutionizing The Future Of Photographic PrintsDigital C-Type Printing: Revolutionizing The Future Of Photographic Prints
Digital C-Type Printing: Revolutionizing The Future Of Photographic PrintsMatte Image
 
Russian Call Girls In Bhubaneswar 📱 Odisha 9777949614 Indore
Russian Call Girls In Bhubaneswar 📱 Odisha 9777949614 IndoreRussian Call Girls In Bhubaneswar 📱 Odisha 9777949614 Indore
Russian Call Girls In Bhubaneswar 📱 Odisha 9777949614 IndoreCall Girls Mumbai
 
Sonbhadra Escorts 📞 8617370543 | Sonbhadra Call Girls
Sonbhadra  Escorts 📞 8617370543 | Sonbhadra Call GirlsSonbhadra  Escorts 📞 8617370543 | Sonbhadra Call Girls
Sonbhadra Escorts 📞 8617370543 | Sonbhadra Call GirlsNitya salvi
 
Theoretical Framework- Explanation with Flow Chart.docx
Theoretical Framework- Explanation with Flow Chart.docxTheoretical Framework- Explanation with Flow Chart.docx
Theoretical Framework- Explanation with Flow Chart.docxAman119787
 

Último (20)

Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4
 
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
 
codes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptxcodes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptx
 
HUMA Final Presentation About Chicano Culture
HUMA Final Presentation About Chicano CultureHUMA Final Presentation About Chicano Culture
HUMA Final Presentation About Chicano Culture
 
THE ARTS OF THE PHILIPPINE BALLET PRESN
THE ARTS OF  THE PHILIPPINE BALLET PRESNTHE ARTS OF  THE PHILIPPINE BALLET PRESN
THE ARTS OF THE PHILIPPINE BALLET PRESN
 
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
 
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
 
WhatsApp-(# 9711106444 #)Call Girl in Noida Sector 80 Noida (Escorts) Delhi
WhatsApp-(# 9711106444 #)Call Girl in Noida Sector 80 Noida (Escorts) DelhiWhatsApp-(# 9711106444 #)Call Girl in Noida Sector 80 Noida (Escorts) Delhi
WhatsApp-(# 9711106444 #)Call Girl in Noida Sector 80 Noida (Escorts) Delhi
 
Russian Call Girls Pilibhit Just Call 👉👉 📞 8617370543 Top Class Call Girl Ser...
Russian Call Girls Pilibhit Just Call 👉👉 📞 8617370543 Top Class Call Girl Ser...Russian Call Girls Pilibhit Just Call 👉👉 📞 8617370543 Top Class Call Girl Ser...
Russian Call Girls Pilibhit Just Call 👉👉 📞 8617370543 Top Class Call Girl Ser...
 
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
 
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
 
Nehru Nagar, Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genui...
Nehru Nagar, Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genui...Nehru Nagar, Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genui...
Nehru Nagar, Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genui...
 
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
 
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
 
Call Girls In Firozabad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Firozabad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Firozabad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Firozabad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
 
Digital C-Type Printing: Revolutionizing The Future Of Photographic Prints
Digital C-Type Printing: Revolutionizing The Future Of Photographic PrintsDigital C-Type Printing: Revolutionizing The Future Of Photographic Prints
Digital C-Type Printing: Revolutionizing The Future Of Photographic Prints
 
Russian Call Girls In Bhubaneswar 📱 Odisha 9777949614 Indore
Russian Call Girls In Bhubaneswar 📱 Odisha 9777949614 IndoreRussian Call Girls In Bhubaneswar 📱 Odisha 9777949614 Indore
Russian Call Girls In Bhubaneswar 📱 Odisha 9777949614 Indore
 
Sonbhadra Escorts 📞 8617370543 | Sonbhadra Call Girls
Sonbhadra  Escorts 📞 8617370543 | Sonbhadra Call GirlsSonbhadra  Escorts 📞 8617370543 | Sonbhadra Call Girls
Sonbhadra Escorts 📞 8617370543 | Sonbhadra Call Girls
 
Theoretical Framework- Explanation with Flow Chart.docx
Theoretical Framework- Explanation with Flow Chart.docxTheoretical Framework- Explanation with Flow Chart.docx
Theoretical Framework- Explanation with Flow Chart.docx
 

Week3.pptx

  • 2. Main Menu A main menu is what is displayed at the start of any program. It should be kept in a function and mainly includes an IF statement. An example of a main menu using last weeks code is: Remembering to use .upper() for validation.
  • 3. Activity Using what you have just learnt, Help • Remember to use IF and ELIF statements for each option as the ELSE statement should be used if the user enters anything that isn’t an option. • Also remember to use .upper() as a basic form of validation. Create a main menu for your code from last week.
  • 4. First Project Layout To achieve this, we will be using the import command to import into our project, our first Python library. The layout of the project will be: - Main Menu - Rock Paper Scissors against AI - Tic Tac Toe against either AI or another player
  • 5. Setup Activity Before we get ahead of ourselves: Further activity Create a new folder called “Python Game Project”. Create a new file called “main.py” Create a function for the main menu with three options: • Rock Paper Scissors • Tic Tac Toe • Exit Create two functions: • rockpaperscissors() • tictactoe() The main menu should call these functions respectively Try and place the main menu in a while loop for validation, that is only exited if the user inputs the exit choice of the menu.
  • 6. The main menu should look like this Console output:
  • 7. The Further activity main menu should look like this Console output:
  • 8. Random Library A library is a collection of prewritten python functions that we can use. The one we will be using today is the “random” library. Standard practice is to place all your imports at the top of the code. Random.randint() is the command to pick a number between the first integer and the second integer (including both of them). An example of the random and random.randint() code is: This code will print a random number of either 1, 2, or 3.
  • 9. Rock Paper Scissors Now is the time to flex your skills. I will let you guys crack on but here is how I would lay out the program: • Import random • Ask the user what they would like to pick • Print what the computer decided on (1 = Rock, 2 = Paper, 3 = Scissors) • Compare the two values • Print if it is a win, lose or draw • Ask the user to play again (optional) • Return to main menu Help • Compare the users input with numbers to make your life easier • Remember “AND” for comparing values in the IF statement. • There will be a lot of IF statements in this program so do not worry if you have a lot. • Also remember to use .upper() as a basic form of validation.
  • 10. Rock Paper Scissors For more help here is the comparison code: • Import random • Ask the user what they would like to pick • compChoice = Randint(1,3) • Convert that to a words • Print what the computer decided on (1 = Rock, 2 = Paper, 3 = Scissors) • Compare the two values • Print if it is a win, lose or draw • Ask the user to play again (optional) • Return to main menu Help
  • 11. Rock Paper Scissors Here is the full code:
  • 12. Arrays An array is a special variable that can be used to store multiple values in one single variable. To access a value in the array you would write the arrays name and then the index of the value you want in square brackets. An example of an array is: 0 1 2 3 This would print the word “Is” as the first value of the array is called 0.
  • 13. Tic Tac Toe Now this is the ultimate challenge. How I would go about it: • Create a Board Array to store what spots are empty. • PrintTable() Function • Pick which player one, will be (X or O) • Compare the win conditions of the slots • When the board is filled, print it was a draw. • Ask the user to play again (optional) • Return to main menu Help • Print the table with “–” and “|” • Use board[x] to pick a certain value in the list. • Having the win conditions in a test function will help you repeatedly check if anyone has won. • Also remember to use numbers for the nine slots.
  • 14. Tic Tac Toe Here is some code for printing the board: How I would go about it: • Create a Board Array to store what spots are empty. • PrintTable() Function • Pick what player one will be (X or O) • Compare the win conditions of the slots • When the board is filled, print it was a draw. • Ask the user to play again (optional) • Return to main menu Help
  • 15. Tic Tac Toe Here is some code for validation: Help The win conditions for Tic-Tac-Toe:
  • 16. Tic Tac Toe Here is the code for entering a position:
  • 17. Tic Tac Toe Here is the code for: • Checking if anyone has won • Swapping between players • And asking the user if they want to play again.
  • 18. Home Activity Combining what you have learnt today, Try and make a computer opponent version of Tic-Tac-Toe using randint() to pick their turns.
  • 19. End of week Three And have a good Christmas