In this project, you ll learn how to create 2 random teams from a list of players. Start by adding a list of players to your program.

Similar documents
In this project you will learn how to write a Python program telling people all about you. Type the following into the window that appears:

Before displaying an image, the game should wait for a random amount of time.

Memory. Introduction. Scratch. In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

Where's the Treasure?

In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

Create Your Own World

Let s start by making a pencil, that can be used to draw on the stage.

Brain Game. Introduction. Scratch

Rock, Paper, Scissors

Add in a new ghost sprite, and a suitable stage backdrop.

Create Your Own World

Some code for this game has been provided for you. Open this trinket: This is a very basic RPG game that only has 2 rooms. Here s a map of the game:

In this project you ll learn how to create a times table quiz, in which you have to get as many answers correct as you can in 30 seconds.

In this project you ll learn how to create a platform game, in which you have to dodge the moving balls and reach the end of the level.

Lost in Space. Introduction. Scratch. You are going to learn how to program your own animation! Activity Checklist.

How to create a survey with SurveyMonkey

Introduction to R and R-Studio Save Your Work with R Markdown. This illustration Assumes that You Have Installed R and R-Studio and knitr

Let s start by making a pencil that can be used to draw on the stage.

Whack-a-Witch. Level. Activity Checklist Follow these INSTRUCTIONS one by one. Test Your Project Click on the green flag to TEST your code

Fireworks. Level. Introduction: In this project, we ll create a fireworks display over a city. Activity Checklist Follow these INSTRUCTIONS one by one

2: Turning the Tables

Creating Computer Games

Introduction to R and R-Studio Introduction to R Markdown and Knitr

Alright! I can feel my limbs again! Magic star web! The Dark Wizard? Who are you again? Nice work! You ve broken the Dark Wizard s spell!

In this project we ll make our own version of the highly popular mobile game Flappy Bird. This project requires Scratch 2.0.

Create a Simple Game in Scratch

In this project you ll learn how to create a game, in which you have to match up coloured dots with the correct part of the controller.

Create a "Whac-a-Block" game in Minecraft

Open the Tech Toys Scratch project. Your club leader will give you a copy of this project, or you can open it online at jumpto.cc/toys-go.

1. Click the Create a Tournament Button (see Challonge Screen 01)

Ghostbusters. Level. Introduction:

Rock Band. Introduction. Scratch. In this project you ll learn how to code your own musical instruments! Activity Checklist.

ChatBot. Introduction. Scratch. You are going to learn how to program your own talking robot! Activity Checklist. Test your Project.

More Actions: A Galaxy of Possibilities

Create a game in which you have to guide a parrot through scrolling pipes to score points.

In this project you ll learn how to create a game in which you have to save the Earth from space monsters.

Girls Programming Network. Scissors Paper Rock!

How To Handbook For Learners

Clone Wars. Introduction. Scratch. In this project you ll learn how to create a game in which you have to save the Earth from space monsters.

GRINDHOUSE MOVIE POSTERS

Flappy Parrot Level 2

Part I: The Swap Puzzle

In this project you ll learn how to code your own musical instruments!

Part II: Number Guessing Game Part 2. Lab Guessing Game version 2.0

Fish Chomp. Level. Activity Checklist Follow these INSTRUCTIONS one by one. Test Your Project Click on the green flag to TEST your code

Writing Interactive Fiction With Adrift

Kaltura CaptureSpace Lite Desktop Recorder: Editing, Saving, and Uploading a Recording

In this project, you ll design and code improvements to a 2D version of Minecraft.

Your First Game: Devilishly Easy

Unit 5: What s in a List

Pong Game. Intermediate. LPo v1

Scratch for Beginners Workbook

How to Build a LimeSurvey: The Basics for Beginners

Lesson 8 Tic-Tac-Toe (Noughts and Crosses)

When you load GarageBand it will open a window on your desktop that will look like this:

Explore and Challenge:

Welcome to Storyist. The Novel Template This template provides a starting point for a novel manuscript and includes:

Programming with Scratch

Competitive Games: Playing Fair with Tanks

Step 1 : Earth and Mars Orbit the Sun

Creating Photo Borders With Photoshop Brushes

Introduction to R and R-Studio Introduction to R Markdown and Knit

Term Definition Introduced in:

SPLAT MINECRAFT [ CHAPTER EIGHT ] Create an exciting two-player game in Minecraft: Pi, inspired by Nintendo s hit game game Splatoon ESSENTIALS

Assignment 5 due Monday, May 7

AIM OF THE GAME GLACIER RACE. Glacier Race. Ben Gems: 20. Laura Gems: 13

Storyist is a creative writing application for Mac OS X 10.9 Mavericks or later. Designed specifically for novelists and screenwriters, it provides:

CS61B, Fall 2014 Project #2: Jumping Cubes(version 3) P. N. Hilfinger

PivotTables PivotCharts (Chapter 5)

5: The Robots are Coming!

EDUCATION GIS CONFERENCE Geoprocessing with ArcGIS Pro. Rudy Prosser GISP CTT+ Instructor, Esri

Assessment. Self Assessment. Teacher Assessment. Date Learning Objective(s) Achievement or. NC Level: Game Control Student Booklet P a g e 1

Write algorithms with variables. Phil Bagge code-it

UNDERSTANDING LAYER MASKS IN PHOTOSHOP

PebblePad LEARNER HANDBOOK

The purpose of this document is to help users create their own TimeSplitters Future Perfect maps. It is designed as a brief overview for beginners.

Creating Journey In AgentCubes

by Jonathan Pickup fourth edition written with version 2013 Vectorworks Landmark Tutorial Manual SAMPLE

make the most of our VISIT SOUTHEND .CO.UK BRAND NEW WEBSITE PROMOTE YOUR BUSINESS, OFFERS & EVENTS FOR FREE

Pass-Words Help Doc. Note: PowerPoint macros must be enabled before playing for more see help information below

Roommate & Room Selection Process

Introduction to Parametric Modeling AEROPLANE. Design & Communication Graphics 1

Pensions YEARLY REVIEW EMPLOYER GUIDE

An easy user guide AN EASY USER GUIDE

Sheets Happen! Using the Sheet Set Manager

Scorer with BridgePads Quick Guide to Teams Scoring

CPSC 217 Assignment 3

Welcome to the Sudoku and Kakuro Help File.

SHAPE CLUSTER PHOTO DISPLAY

Submitting Your Manuscript to ScholarOne Manuscripts: A Guide. To submit your manuscript, you will need the following files:

GameSalad Basics. by J. Matthew Griffis

BIM - ARCHITECTUAL IMPORTING A SCANNED PLAN

Try what you learned (and some new things too)

Candidate FAQ. Table of Contents

2D Platform. Table of Contents

Cato s Hike Quick Start

How to Add Fake Smoke/ Mist to your Pictures

Photoshop Weather Effects Rain

Drawing Layouts Paper space & Model Space

Overview. The Game Idea

Transcription:

Team Chooser Introduction: In this project, you ll learn how to create 2 random teams from a list of players. Step 1: Players Let s start by creating a list of players to choose from. Activity Checklist Open the blank Python template Trinket: jumpto.cc/python-new. You can use a variable to store a list of players. The list should be in square brackets [ ], with a comma between each item in the list. Start by adding a list of players to your program. Add this code to print your players variable: 1

You can get to an item in the list by adding its position in square brackets after the variable name. The first item in the list is at position 0. This is different to Scratch, which starts at position 1. Challenge: Adding more players Can you add more players to your list? You can add as many players as you like, but make sure that there is an even number of players. You can also change the names of the first 2 players if you prefer. Can you add code to print just one of your new players? Step 2: Random players Let s choose random players! Activity Checklist 2

To be able to get a random player from your players list, first you ll need to import the choice part of the random module. To get a random player, you can use choice. (You can also delete the code to print individual players.) Test your choice code a few times and you should see a different player being chosen each time. You can also create a new variable called playera, and use it to store your random player. You ll need a new list to store all of the players in team A. To start with, this list should be empty. 3

You can now add your randomly chosen player to teama. To do this, you can use teama.append (append means add to the end). Now that your player has been chosen, you can remove them from your list of players. Test this code by adding a print command, to show the players left to choose from. In the example above, Hermione has been chosen for teama, and so 4

has been removed from the list of players. Challenge: Choosing for team B Can you add code to choose a player at random for team B? You ll need to: Create a new teamb list Choose a random player for team B (called playerb ) append the chosen player to your teamb list remove the chosen player from your list of players The code you ll need for teamb will be very similar to the code you ve already written for teama! Step 3: Choosing lots of players Next you ll need to make sure that every player has been chosen for a team. Activity Checklist Highlight your code for choosing players for team A and team B and press the tab key to indent the code. 5

Add a while loop to keep choosing players until the length of the players list is 0. Run your code to test it. You should see players being chosen for team A and team B until there are no more players left. 6

Add code to print your teama list after your while loop (making sure it is not indented). This means that teama will only be printed once, after all the players have been chosen. You can do the same for teamb, and you can also delete the other print commands, as they were only there to test your code. Here s how your code should look: 7

Test your code again and you should just see your list of players as well as your final teams. Step 4: Files You can use a file to store your list of players. Activity Checklist Click the + icon and create a new file called players.txt. 8

Add your players to your new file. Make sure that there is no blank line after your last player. Change your players list so that it is empty. Open your players.txt file (the 'r' means read-only). Read the list from the file and add to your players list. (The splitlines code means that every line in the file is a new item in the players list). 9

If you test your code, it should work exactly the same as before. However, now it s much easier to add players to your players.txt file. Step 5: Odd players Let s improve your program to work with an odd number of players. Activity Checklist Add another name to your players.txt list, so that you have an odd number of players. If you test your code, you ll see that you get an error message. 10

The error is because your program keeps choosing random players for team A and then team B. However, if there is an odd number of players then after choosing a player for team A there are no players left to choose from for team B. To fix this bug, you can tell your program to break out of your while loop if your players list is empty. If you test your code again, you should see that it now works with an odd number of players. 11

Challenge: Random team names Can you give both of your teams a random team name? You can create a list called teamnames containing the names to choose from. You can then choose (and display) a random name for each team. Challenge: Storing team names Can you store your list of team names in a file? Challenge: More teams 12

Can you improve your program to split players into 3 teams instead of 2? 13