COMPUTER SCIENCE CAFÉ
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
CODING CHALLENGES | ITERATION
Enjoy the journey of learning to code, explore and be creative
ON THIS PAGE
CHALLENGE 1 | TIMES TABLES
CHALLENGE 2 | PASSWORD CHECK
​CHALLENGE 3 | NESTED FOR
CHALLENGE 4 | FIBONACCI
​CHALLENGE 5 | VOTING SYSTEM - WHILE FOR IF
CHALLENGE 6 | NUMBER GUESSING GAME 
CHALLENGE 7 | GHOST TYPING
CHALLENGE 8 | COUNTDOWN TO LIFT OFF
Picture
SUBSCRIBE FOR SAMPLE SOLUTIONS
ALSO IN THIS TOPIC
LEVEL 1 | GETTING STARTED
 LEVEL 2 | VARIABLES AND USER INTERACTION
LEVEL 3 | DATATYPES AND OPERATORS
 LEVEL 4 | IF STATEMENTS
YOU ARE HERE | LEVEL 5 | LOOPS
​LEVEL 6 | ARRAYS / LISTS
LEVEL 7 | FUNCTIONS
LEVEL 8 | ALGORITHM DESIGN
LEVEL 9 | OOP
LEVEL 10 | EXTERNAL DATA HANDLING
TURTLE CHALLENGES
DEBUGGING AND TRACING​
CHALLENGE SOLUTIONS

Picture
WATCH THIS VIDEO TO HELP YOU WITH THIS SECTION
Picture
CHALLENGE 1 | TIMES TABLES
Create a program to do the following:
A: Ask the user which times tables they want to output 'Which times tables do you want to see?'
B: Use a FOR loop to output the times table from 1 - 10
EXAMPLE OUTPUT
Which times tables do you want to see?  7
7
14
21
28
35
42
29
56
63
70
EXTENSION TASK
Make your program more user friendly by adding a note before each output, for example:
1 x 7 is: 7
2 x 7 is: 14
Picture
CHALLENGE 2 | PASSWORD CHECK
Create a program using a WHILE loop and IF statement to check a password:
A: Create a variable called 'password' and assign the value 'qwerty' to the variable
B: Create a WHILE loop to continue until the correct password is entered
C: Ask the user to enter a password. 'Please enter your password'
D: If the password entered is equal to the value stored in the variable 'password' (qwerty)
     then break the loop and output a welcome message. 'Welcome, your password was correct'
E: If the user enters the incorrect password
    then output a message for them to try again 'You entered the wrong password, please try again'
F: You program should continue to loop until the correct password is entered.
EXAMPLE OUTPUT
​Please enter your password : password
You entered the wrong password, please try again.
​Please enter your password :
mypassword
​
You entered the wrong password, please try again.
​Please enter your password : 
qwerty
Welcome, your password was correct
Picture
​CHALLENGE 3 | NESTED FOR
Scenario: A teacher is hosting running race and she wants to print out a template to record the results. 
Create a program to do the following:

A: Ask the teacher how many races there will be. How many races will there be?
B: Ask the teacher how many students she has: How many students are racing? 
C: Use a FOR loop to create the race number - for example Race 1
D: Nest a FOR loop (put a loop inside your loop) to create the template for the student result.
E: Output a title for the sheet, for example 'RACE TEMPLATE'
E: Output the template ready for the teacher to print and record her results 
NOTE: Do not write the numbers in yourself, let your program do the work for you.
EXAMPLE OUTPUT
How many races will there be? 2
How many students are racing? 4
RACE TEMPLATE
RACE 1
STUDENT 1 :
STUDENT 2 :
STUDENT 3 :
STUDENT 4 :
RACE 2
STUDENT 1 :
STUDENT 2 :
STUDENT 3 :
​STUDENT 4 :
Picture
CHALLENGE 4 | FIBONACCI
The Fibonacci numbers are a beautiful set of numbers created in mathematics and the pattern is seen everywhere in nature. In the sequence the next number is the product of the addition of the previous two numbers. For more details on the Fibonacci sequence watch this video by SciShow.
Create a program to do the following:
1: Use a FOR loop to output the first 10 in the sequence of the Fibonacci numbers.
EXPECTED OUTPUT:
1
1
2
3
5
8
13
21
34
55
TASK TIP
It might help to set up 2 or 3 variables to store the first numbers before you create the loop.
Picture
​CHALLENGE 5 | VOTING SYSTEM
Create a program that allows people to vote and checks the number and validity of the vote:
A: Create 3 variables to store the votes. vote1, vote2 and vote3
1: Ask the user if they are ready to vote. Are you ready to vote Yes/No?
2: If the user is not ready to vote then output 'Ok, have a great day'. Then end the program.
3: If the user is ready to vote then output the voting list.
Here is the list of people you can vote for.

1: Jane
2: Bob
3: Jill
4: Dave
5: Bill
6: Wendy
7: Larry
8: Ada
9: Jenny
​10: Tilly

4:  Allow the user to vote for three people by entering the voting number for each.
5: If the user enters an invalid voting number, then ask the user for that vote again. 
6: Your WHILE loop should continue to loop until you have 3 valid votes.
7: After the loop has finished, output the final candidates the user has voted for.
​8: Check your program does not break/have runtime errors at any point.
EXAMPLE OUTPUT
Are you ready to vote Yes/No? Yes
​Here is the list of people you can vote for.
0: Finished Voting
1: Jane
2: Bob
3: Jill
4: Dave
5: Bill
6: Wendy
7: Larry
8: Ada
9: Jenny
​10: Tilly

Vote 1: Please enter your vote - enter 1 - 10 or 0 to finish voting: 4
Vote 2: Please enter your vote - enter 1 - 10 or 0 to finish voting: Q
You entered an invalid value, please try again.
Vote 2: Please enter your vote - enter 1 - 10 or 0 to finish voting: 1
Vote 3: Please enter your vote - enter 1 - 10 or 0 to finish voting: 10
Thank you for voting the following candidate numbers: 4, 1, 10
Picture
CHALLENGE 6 | NUMBER GUESSING GAME 
Create a program that generates a random number and allow the user to try and guess the number:
1: Generate a random number or use the two lines of code below to generate a random number, firstly to import random, secondly to produce a random number and save it in a variable called 'num'.
#FOR PYTHON CODERS - HOW TO GENERATE A RANDOM NUMBER
import random
num = random.randint(1,20)

2: Create a variable to hold the score and set the starting score to 10
3: Ask the user to guess a number.
​4: IF the user guesses too high then output 'You guess too high, please guess again'. Deduct 2 points from the score.
4: IF the user guesses too low then output 'You guess too low, please guess again'. Deduct 2 points from the score.
​5: IF the user guesses correct then output 'You guess correct, well done!'. Output the score.
6: IF the score is 0 then output end this game and output 'Game Over !!!"
7: Ask the user if they want to play again.
8: If the user wants to play again the generate a new number and loop back through your code. Do not duplicate your code.

9: IF the user does not want to play again the end the program.
10: Ensure your program does not crash, for example if the user enters a letter instead of a number a error message should be given and the user asked again for the number.
EXAMPLE OUTPUT
Please guess a number between 1 and 20: 14
Your score is now 8
You guess too low, please guess again: qwerty
You entered an invalid input, please try again: 10
Your score is now 6
You guess too low, please guess again: 18
Your score is now 4
You guess too high, please guess again: 15
You guess correct, well done! 
You scored 4
Would you like another game? No
Ok, thank you for playing
Picture
CHALLENGE 7 | GHOST TYPING
Create a program that will simulate typing using a string of words and adding a time delay between letters:
1: Create a variable to hold the sentence you want to be typed.
2: Create a loop to iterate through each letter within the string
3: Add a short delay between each loop so each letter appears in a realistic typing time - you will need to import time

EXTENTION TASK:
Add to your program by changing the time delay between each letter to be random. Make it look even more realistic!

NOTE: In python you may wish to use:
sys.stdout.write(your_sentance)
sys.stdout.flush()
Picture
CHALLENGE 8 | COUNTDOWN TO LIFT OFF
Create a program that uses a loop to count down and output from 10 to 1 and then BLAST OFF at zero.
​NOTE: Avoid doing this with manually type something like count = count - 1.
10
9
8
7
6
5
4
3
2
1
BLAST OFF !!!!

EXTENSION:  Import time to add a delay the the countdown. Example code in Python:
import time
time.sleep(1)
Picture
Picture
NAVIGATION
LEVEL 1 | GETTING STARTED
LEVEL 2 | VARIABLES AND USER INTERACTION
LEVEL 3 | DATATYPES AND OPERATORS
LEVEL 4 | IF STATEMENTS
LEVEL 5 | LOOPS
​LEVEL 6 | ARRAYS / LISTS
LEVEL 7 | FUNCTIONS
LEVEL 8 | ALGORITHM DESIGN
LEVEL 9 | OOP
LEVEL 10 | EXTERNAL DATA HANDLING
TURTLE CHALLENGES
DEBUGGING AND TRACING​
CHALLENGE SOLUTIONS
Picture
SUGGESTIONS
We would love to hear from you
SUBSCRIBE 
To enjoy more benefits
We hope you find this site useful. If you notice any errors or would like to contribute material then please contact us.