• Python Programming Challenges

      Programing is a fundamental aspect of computing, IT and Games industries. Everyone who wants to be involved in one of these industries needs to have the ability the problem solve and develop solutions in logical manner. Complete our Python programming challenge to test your skills!

      Instructions:

      ·         Use https://repl.it/languages/python3 to generate and test your code.

      ·         For each task, it is recommended that you plan the program using pseudocode BEFORE you create it

      ·         When you have created the program in Python get verification that it does function as planned

      Rules

      ·         Complete the tasks in any sequence

      ·         Make sure that you save your solutions to your Python folder on D Drive

      ·         You cannot use the Internet to find solutions.

      Useful video links and tutorials

      https://www.youtube.com/watch?time_continue=2&v=wvAblqsEj54&feature=emb_logo

      https://www.youtube.com/watch?time_continue=25&v=Ebh157e3FkQ&feature=emb_logo

      Find out more at Python.org

      Challenge 1: Best friend

      Challenge:

      Write a program that asks for 2 of your friend’s names and then states which friend is the best friend.

      Pseudocode:

       


       

       

      Record

      Completed successfully?

       

      Did you have any errors? What?

       


      Challenge 2: Favourite song

      Try the following code:        

      start = "Hello, "

      name = input("What is your name? ")

      end = ". How are you today?"

      sentence = start + name + end

      Write a program that asks the user what their favourite song is and then asks them for line 1, line 2 and line 3. It should store the first, second and third lines of the song as variables and then add the strings together to output the song.

      Pseudocode:

       


       

       

      Record

      Completed successfully?

       

      Did you have any errors? What?

       


      Challenge 3: Piggybank

      Remember that input() always returns a string. You need to use type casting to convert a string (str) to an integer

      (int) or integer to a string.

      Challenge:

      Write a program that helps the user to add up the coins in their piggy bank. The program should ask:

      “How many pennies”, “How many two pence pieces”, “How many 5 pence pieces” etc. Then it should give the total value of the piggy bank.

      Pseudocode:

       


       

       

      Record

      Completed successfully?

       

      Did you have any errors? What?

       


      Glossary

      Argument

      A piece of information that is required by a function so that it can perform a task

      Bug

      A piece of code that is causing a program to fail or not to run properly

       

      Comments

      Some text in a computer program that is for the human reader and is ignored by the

      computer

       

      Comparison operators

       

      Also called logic operators. They allow us to compare data.

      <      >     <=     >=     !=     = =

       

      Data type

       

      Different types of data stored by the computer – for example integers (numbers), text and floats (decimals)

       

       

      Escape characters

       

      Characters that can be used in Python to ‘break’ a sequence and tell Python that a

      character has a different meaning – examples are         \       \n ( new line)        \t (tab indent)      \\ (allows a back slash in a string)                         \” allows speech marks to be used in a string without ending the string

      Float

      A decimal number

      For loop

      A loop that repeats code for a specified number of times

      Function

      A reusable piece of code

      Infinite loop

      A piece of code that keeps running forever

      Integer

      A number data type – a whole number

      Loop

      A piece of code that repeats until a specified condition is met

       

      Mathematical operators

       

      An operator that performs a mathematical calculation, such as              +      -     /      *      **   %

       

      Module

       

      A saved python file whose functions can be used by another program (eg import time –

      imports the time module)

      Output

      Data that is sent from the program to the screen or printer or other output device

      Pseudocode

       

      String

      Text data

      Syntax

      The format of the code

       

      Syntax error

       

      An error produced when a computer fails to run a program because it cannot recognise the format of the code – for example a bracket has not been closed

       

      Testing

      Where the program created is run repeatedly using different inputs and conditions to

      check that it works and runs correctly – every possibility has to be checked.

      Type casting

      The process of converting a data type to another – eg converting an integer to a string

       

      Variable

       

      A name given to a piece of data that is then stored in the memory and then is used to refer to that data

      While loop

      A loop that repeats code while a condition is being met (eg while n < 10)



    • If you enjoyed the above challenges you can keep going with these more complex tasks!

      Challenge 4: Customer Discount

      A shop is having a sale. They’re giving 10% off when a customer spends £10 or less and 20% off when they spend over £10. Write a program that asks for the amount spent and then displays the discount to be applied and then the final price (ie with the discount applied)

      Pseudocode:

       


       

       

      Record

      Completed successfully?

       

      Did you have any errors? What?

       


      Challenge 5: Piggybank 2

      Remember that programs can make decisions based on the input of the user – it checks IF a condition is met and IF not it can do something ELSE.

      To compare values we need to use comparison operators such as: <            >          <=        >=        !=

      Challenge:

      Using your Piggybank program from challenge 3; develop the program so that if the users savings add up to less than £50 it tells them to save more and if it is over £50 it tells them that they’re doing well.

      Pseudocode:

       


       

       

      Record

      Completed successfully?

       

      Did you have any errors? What?

       







      Challenge 6: Blast off

      Look at the code:              

      number = 1

      while number < 101:

      print (number)

      number = number +1

      Challenge:

      Write a program that counts a blast off sequence for a space rocket, counting down from 10 and then saying ‘BLAST OFF’ . You will need to use the import time function and use a count variable.

      Pseudocode:

       


       

       

      Record

      Completed successfully?

       

      Did you have any errors? What?

       


      Challenge 7: Times table

      Write a program to print a multiplication table (a times table). At the start it should as the user which number they want to see the times table for by asking “Which times table would you like?”

      Hints: you will need to use 2 variables and one of these will be the user input (the times table wanted). Example output:              

      Which times table would you like?

      5

      Here’s your table:

      5 x 1 = 5……..

      Pseudocode:

       


       

       

      Record

      Completed successfully?

       

      Did you have any errors? What?

       


      Challenge 8: Rolling the dice

      Remember this?

      Try it:

      import random

      n = random.randint(1,100)

      print (n)

      Challenge:

      Write a program that simulates (acts like) rolling a die. The program should ask the user if they want to roll the dice, while they say yes it should tell them the number they have rolled (“You have rolled a “). It should ask them again after each roll. If they say no, the program should say ‘Goodbye’

      Pseudocode:

       



       

       

      Record

      Completed successfully?

       

      Did you have any errors? What?

       



    • There are a range IT related A Level and BTEC courses available to study at Huddersfield New College. To find out more, click on the course guides below.

      A Level Computer Science

      BTEC Computing

      BTEC Information Technology