Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python Programming: Higher or Lower Game, Study notes of Advanced Computer Programming

The objectives and planning for a python programming exercise called 'the higher or lower game'. The game involves generating a random number between 1 and 100, and asking the user to guess the number. How to use variables, if-else statements, and loops to implement the game. Extensions to the game include allowing the user to choose the difficulty level, counting attempts, and giving a rating based on score.

What you will learn

  • How can you implement the 'Higher or Lower Game' with different difficulty levels?
  • What is the role of a loop in the 'Higher or Lower Game'?
  • How can you generate a random number in Python?

Typology: Study notes

2021/2022

Uploaded on 09/12/2022

butterflymadam
butterflymadam 🇺🇸

4.4

(26)

312 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python'Programming''The'Higher'Or'Lower'Game'
!
Objectives'
!
By!the!end!of!this!lesson!you!should!be!able!to:!
Generate!a!random!number!
!
Ask!the!user!for!a!value!and!store!it!in!a!variable!
!
Use!an!IF…ELIF…ELSE!statement!
You!might!be!able!to:!
Use!a!WHILE!loop!to!repeat!code!until!some!rule!is!met!
!
Use!a!counter!to!keep!track!of!how!many!times!you!have!used!a!loop!
!
The'Task'
!
You!have!been!asked!to!write!a!simple!version!of!the!“higher!–!lower!game”.!The!
game!works!like!this:!
The!computer!generates!a!random!whole!number!between!1!and!100.!
This!is!the!target!number.!
!
The!user!is!asked!to!enter!a!guess!
!
If!the!guess!is!higher!than!the!target!number,!the!computer!will!print!out!
Too!high!”!
!
If!the!guess!is!lower!than!the!target!number,!the!computer!will!print!out!
Too!low!”!
!
If!the!guess!is!correct,!the!computer!will!print!out!“Correct!”!
!
Planning'
You!will!need!to!use!2!variables.!
Choose!a!suitable!name!for!the!variable!that!will!hold!the!target!number:!
!
Choose!a!suitable!name!for!the!variable!that!will!hold!the!guess:!
!
pf2

Partial preview of the text

Download Python Programming: Higher or Lower Game and more Study notes Advanced Computer Programming in PDF only on Docsity!

Python Programming – The Higher Or Lower Game

Objectives

By the end of this lesson you should be able to:  Generate a random number  Ask the user for a value and store it in a variable  Use an IF…ELIF…ELSE statement You might be able to:  Use a WHILE loop to repeat code until some rule is met  Use a counter to keep track of how many times you have used a loop

The Task

You have been asked to write a simple version of the “higher – lower game”. The game works like this:

  • The computer generates a random whole number between 1 and 100. This is the target number.
  • The user is asked to enter a guess
  • If the guess is higher than the target number, the computer will print out “Too high!”
  • If the guess is lower than the target number, the computer will print out “Too low!”
  • If the guess is correct, the computer will print out “Correct!”

Planning

You will need to use 2 variables. Choose a suitable name for the variable that will hold the target number : Choose a suitable name for the variable that will hold the guess :

Python Programming – The Higher Or Lower Game

Extensions

  • After the first guess, repeat (with the same target number) until the user gets the correct answer.
  • The computer will count how many attempts the user took an print out a score.
  • The computer will give the user a rating based on their score.
  • Before starting the game, give the user a choice of difficulties (each with a different range for the random numbers – easy might be 1 to 50, hard might be -­‐500 to +500).
  • Include a special value the user can guess that will mean “I give up” and will show the user the correct value.

Objectives

Tick the box if you are able to:  Generate a random number  Ask the user for a value and store it in a variable  Use an IF…ELIF…ELSE statement  Use a WHILE loop to repeat code until some rule is met  Use a counter to keep track of how many times you have used a loop