Quiz. Introduction: Python. In this project, you ll make a quiz game to challenge your friends. Activity Checklist.

Similar documents
ASCII Art. Introduction: Python

You will be writing code in the Python programming language, which you may have learnt in the Python module.

Text Input and Conditionals

A cipher is a type of secret code, where you swap the letters around so that noone can read your message.

Decisions, Decisions. Testing, testing C H A P T E R 7

In this project, you ll learn how to create your own webpage to tell a story, joke or poem. Think about the story you want to tell.

RETURN X return X Returning a value from within a function: computes the value of variable exits the function and returns the value of the variable

Memorandums. Keyboarding Objective 4.03 Apply correct memo and letter formats.

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

In this project, you ll learn how to use a turtle to draw awesome shapes and patterns.

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

Flow Control: Branches and loops

Outline. Announcements. Homework 2. Boolean expressions 10/12/2007. Announcements Homework 2 questions. Boolean expression

(Python) Chapter 3: Repetition

RETURN X return X Returning a value from within a function: computes the value of variable exits the function and returns the value of the variable

Self-Teach Exercises: Getting Started Turtle Python

CS 115 Lecture 8. Selection: the if statement. Neil Moore

Shakespeare App. A Multiple Choice Quiz

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Programming with Python

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

StoryStylus Scripting Help

CMPT 120 Control Structures in Python. Summer 2012 Instructor: Hassan Khosravi

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block

CS 105 Lab As a review of what we did last week a. What are two ways in which the Python shell is useful to us?

Comp 151. Control structures.

An Introduction to Python

Mailman Max. The postcode is a great way to work out the next sorting office a letter should go to, so you ll use that.

2 Adding Contacts, Sending Attachment s and Sending s to More Than 1 Person.

NCAA Instructions Nerdy for Sports

Cleaning a Course Shell

Chapter 2 Writing Simple Programs

Unit E Step-by-Step: Programming with Python

How Do Robots Find Their Way?

Flow Control. So Far: Writing simple statements that get executed one after another.

Session 4 Starting the Air Raid Game

Unit 7. 'while' Loops

Introduction to Programming

Exceptions in Java

MITOCW watch?v=0jljzrnhwoi

4.2 Function definitions the basics

A453 Task 1: Analysis: Problem: Solution:

What is netiquette? K34#%^**(11`IJN+}}C>ET34KH<D>Q!:DL=+szd$R4457DGFG^U%*%&^YDFG#$CV%&58w[SRSBFy>

BB4W. KS3 Programming Workbook INTRODUCTION TO. BBC BASIC for Windows. Name: Class:

Introduction to CS. Welcome to CS 5! 1 handout. We don't have words strong enough to describe this class. Everyone will get out of this course a lot!

NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

In this project, you will create a showcase of your HTML projects and learn about links and embedding resources.

CMSC 201 Fall 2018 Lab 04 While Loops

Chapter 1. Data types. Data types. In this chapter you will: learn about data types. learn about tuples, lists and dictionaries

Comp 151. Control structures.

I have bought the game on Steam and played it before the release of update

Word Processing: Basic Skills

Dealer Reviews Best Practice Guide

Burning CDs in Windows XP

Project 1 Balanced binary

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal

The Team Administrator will now be automatically registered to submit results via SMS Text Message.

9.2 Linux Essentials Exam Objectives

Exercise 6 - Addressing a Message

COMP : Practical 9 ActionScript: Text and Input

Welcome to Moodle! How To Moodle

Lab 5: Dreamweaver CS5, Uploading your Web site

Control Flow: Branching booleans and selection statements CS GMU

Asking for information (with three complex questions, so four main paragraphs)

Lab 12: Lijnenspel revisited

How to Use ServiceNow

How Your First Program Works

BEGINNER PHP Table of Contents

Built-in functions. You ve used several functions already. >>> len("atggtca") 7 >>> abs(-6) 6 >>> float("3.1415") >>>

CMSC201 Computer Science I for Majors

Boolean Expressions. Is Equal and Is Not Equal

Making Decisions In Python

Boolean Expressions. Is Equal and Is Not Equal

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

Writing a letter quiz

Arrays/Branching Statements Tutorial:

EIN INSTRUCTIONS Read Thru This First, Then Follow Instructions To Get Your EIN

Popcorn's ini Tutorial

CS 3 Midterm 1 Review

Welcome to Getting it read not deleted: The secrets of a good e-newsletter. Nick Day

Math for Liberal Studies

First-Order Translation Checklist

5 R1 The one green in the same place so either of these could be green.

Organising . page 1 of 8. bbc.co.uk/webwise/accredited-courses/level-one/using- /lessons/your- s/organising-

Basics of Programming with Python

class objects instances Fields Constructors Methods static

Shorthand for values: variables

Computer Basics. Need more help? What s in this guide? Types of computers and basic parts. Why learn to use a computer?

Most of the class will focus on if/else statements and the logical statements ("conditionals") that are used to build them. Then I'll go over a few

Accounts and Passwords

Taskbar: Working with Several Windows at Once

Lesson 6 page 1. If you look at the bottom right of the Scratch color choices, you will see it say MORE BLOCKS in Purple.

Excel Basics: Working with Spreadsheets

CS125 : Introduction to Computer Science. Lecture Notes #11 Procedural Composition and Abstraction. c 2005, 2004 Jason Zych

CMSC 201 Spring 2017 Lab 12 Recursion

Functions and Decomposition

Transcription:

Python 1 Quiz All Code Clubs must be registered. Registered clubs appear on the map at codeclub.org.uk - if your club is not on the map then visit jumpto.cc/18cplpy to find out what to do. Introduction: In this project, you ll make a quiz game to challenge your friends. Activity Checklist Test your Project Save your Project Follow these INSTRUCTIONS one by one Click on the green flag to TEST your code Make sure to SAVE your work now 1

Step 1: Asking a question Activity Checklist 1. Let s start by writing a very simple quiz program that asks the player a question, then shows them smiley faces if they input the correct answer. print("in Python, what do you call a 'box' used to store data?") answer = input() if answer == "variable": print(" :) " * 100) print("thank you for playing!") Take care to add the colon ( : ) to the end of the line if answer == "variable":, and indent the line below it (move it to the right) with spaces. 2. Once you ve written the program above, try it out! What happens when you get the answer right? What happens when you get it wrong? The indented code (that prints the smiley faces) only runs if 2

the answer is correct. But Thank you for playing! always appears, whether your answer is right or wrong. Why is that? Python uses two equals signs == to check if two things are the same. This is because one equals sign = is used to store something in a variable (for example answer = input() ). 3. The program above prints smiley faces if the player gets the question right, but doesn t print anything to tell them they got the answer wrong. You can use an else statement to print sad faces if the user inputs anything other than the correct answer. print("in Python, what do you call a 'box' used to store data?") answer = input() if answer == "variable": else: print(" :) " * 100) print(" :( " * 100) print("thank you for playing!") Try out this new program. What happens when you enter the right answer? What happens when you enter anything else? 3

Challenge: Question time Use what you ve learnt so far to create your own quiz. You can choose any topic you like, and your quiz should use if and else statements to let the player know how they re doing. Step 2: Testing It s always a good idea to test your programs, to make sure that they work properly. Activity Checklist 1. If you ve tested your quiz, you may have noticed it s possible to get sad faces even when you input a correct answer! Like in this example, where the player has accidently pressed CAPS LOCK! This happens because Python is very strict when it compares the player s answer to the correct answer. To Python, V isn t the same as v, and so if the player uses any capital letters in their answer, Python thinks the answer s wrong! Test this out in your game, to see if the same thing happens. 4

2. To fix the problem, you need to convert the player s input to lower case, so there are no capital letters in their answer. We can make sure this works by printing the modified answer. Make this change where the player inputs their answer: answer = input().lower() print(answer) 3. Now test your quiz again. Have you fixed the problem? Try testing these examples: Step 3: Multiple choice Activity Checklist 1. So far you ve used if and else to let the player know if they got the answer right or wrong. But what if you wanted a multiple choice question, where the user could see one of 4 messages? You can use an elif statement to do this. 5

print(''' Q1 - In Python, what do you call a 'box' used to store data? a - text b - variable c - a shoe box ''') answer = input().lower() if answer == "a": print(" Nope - text is a type of data :( ") elif answer == "b": print(" Correct!! :) ") elif answer == "c": else: print(" Don't be silly! :( ") print(" You didn't choose a, b or c :( ") elif is short for else if. So in the program above, the player sees one of 4 messages, depending on what they entered for their answer. 2. Add the code above to your quiz, so that you have a multiple choice question. 3. Test this new question 4 times, so that you see each of the 4 messages. 6

Challenge: Multiple choice quiz Add a few multiple choice questions to your quiz program. Once you have finished making your quiz, get someone else to play it! How did they do? Did they enjoy it? Was it too easy or too hard? 7

Challenge: Keeping score Can you use a score variable in your quiz program, to keep track of the player s score? This is how the variable could be used: At the start of the program, set the score to 0. Whenever a question is answered correctly, add 1 to the player s score. ( score = score + 1 ) Print the player s score at the end of the quiz. Challenge: How did I do? Can you print a personalised message to the player at the end of the game? Say well done if they got all of the questions right. else say try again if they got any wrong. (You ll need to use your score variable to decide which message to print!) 8