COMPUTER SCIENCE CAFÉ
  • FOUNDATION YEARS
  • GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • CHALLENGES
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
  • FOUNDATION YEARS
  • GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • CHALLENGES
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
CODING CHALLENGES | FUNCTIONS
Enjoy the journey of learning to code, explore and be creative
ON THIS PAGE
CHALLENGE 1 | CALCULATOR
​CHALLENGE 2 | PASSWORD CHECKER
CHALLENGE 3 | DECISION MAKER
CHALLENGE 4 | ROCK PAPER SCISSORS
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
 LEVEL 5 | LOOPS
 ​LEVEL 6 | ARRAYS / LISTS
YOU ARE HERE | LEVEL 7 | FUNCTIONS
LEVEL 8 | ALGORITHM DESIGN
LEVEL 9 | OOP
LEVEL 10 | EXTERNAL DATA HANDLING
TURTLE CHALLENGES
DEBUGGING AND TRACING​
CHALLENGE SOLUTIONS
Picture
CHALLENGE 1 | CALCULATOR
Create a calculator to add, divide and subtract. Your program should include 4 functions add, divide, subtract and useCalculator.
1: In the useCalculator function
  • Ask the user if they want to use the calculator
  • If the user does not want to use the calculator then end the program
  • If the user does want to use the calculator then ask the user
  1. What would they like to do: Add, Subtract or Divide
  2. Ask for the first number
  3. Ask for the second number
  • Pass the values to the correct function
2: In the 3 calculation functions
  • Receive the values to calculate
  • Perform the calculation and output the answer in a user friendly way
  • Go back to the useCalculator function when done
Picture
​CHALLENGE 2 | PASSWORD CHECKER
You are going to create a program to check a users password, to test the program create a variable called password and set the standard password as "qwerty". Create a count

Create the following 4 functions: login, checkPassword, welcome, delay
1: In the login function
  • Ask the user to enter their name
  • Ask the user to enter their password
  • Call the checkPassword function and send in the details
2: In the checkPassword function
  • Create a count to store incorrect entries
  • Check to see if the password the user entered is the same as the password stored in the variable password
  • If the password is incorrect then add 1 to the count of incorrect entries
  1. If the count reaches 3 then call the function Delay
  2. Ensure the count is reset ready for the next try
  • If the password is correct call the function welcome and send in the details needed
3: In the welcome function
  • Welcome the user and use the users name in your welcome message
4: In the delay function
  • Tell the user they have tried too many times and they need to wait to try again, ensure you use the users name in the message
  • Create a short delay using a method such as time.sleep(10) (in Python)
  • After the delay return to the login function
Picture
CHALLENGE 3 | DECISION MAKER
Do you ever struggle or argue what to do, what to eat or where to go? Well here you are going to solve that problem.

Before you start create 3 empty lists: where, food and activity
Create a program that has the following 5 functions place, eat, toGo, makeDecision, answer:
1: In the makeDecision function
  • Ask the user if they want to use the program
  • IF the user does not want to use the program then exit
  • IF the user does want to use the program then ask the following
"Do you want a decision on 1: Where to Go? 2: What to Eat? 3: What activity to do?"
  • Ask the user how many options they want in the list
  • Call the relevant function and send in the number of options
2: In the functions place, eat, toGo
  • Create a loop to ask the user to enter the options
  • Use a random selection method to select one of the options
  • Send the chosen option to the answer function
3: In the answer function
  • Receive the value send from one of the functions place, eat or toGo
  • Give the user a user friendly message to say what the decision is
  • Return to the makeDecision function

Extension
Add a pre-made list of activities, food and place's. Keep this ready to use as an option for the future. And add as an option by asking the user if they would like to include these options in the decision making.
Picture
CHALLENGE 4 | ROCK PAPER SCISSORS
Create a Simple Rock-Paper-Scissors Game
Skills required:
  • Understanding of basic programming concepts such as variables, loops and conditionals
  • Basic knowledge of input and output operations
Build a simple Rock-Paper-Scissors game that allows the user to play against the computer. The game should prompt the user to enter their choice (rock, paper or scissors) and then generate a random choice for the computer. The game should then display the result and the number of wins and losses for the user.

Steps to complete the challenge:
Create variables to store the user's choice and the computer's choice.
Create a function to prompt the user to enter their choice (rock, paper or scissors).
Create a function to generate a random choice for the computer using a random number generator. 
Create a function to compare the user's choice and the computer's choice and determine the result of the game.
Create a function to keep track of the number of wins and losses for the user.
Create a function to display the result of the game and the updated win and loss count.
Create a function to allow the user to play again by repeating the process from step 2.

Ensure you use meaningful variable names throughout your program.
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.