Skip to main content

Programming Challenges

The tasks below can be solved in any programming language.

Count Letters in a String

Create a program which will produce read in a string from the user and then print out number of characters in the string.

For example if the user enters "Hello" the program would output the number 5.

Then see if you can work out how to count the number of vowels in a string.

Here's a page on W3 Schools - Python Strings that will help you.

Squares

Create a program that will ask the user for a number and then print out a list of numbers from 1 to the number entered and the square of the number. For example, if the user entered ‘3’
then the program would output:
1 squared is 1
2 squared is 4
3 squared is 9

Times Tables

Create a program which will produce the times table for a number entered by the user
eg if the user enters ‘2’ it should produce:
1 x 2 = 2
2 x 2 = 4
3 x 2 = 6

Averages

Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.

Extensions:

  1. Expand the program to print the median and mode averages also
  2. Include options so that if the user wants to, they can save their list of numbers to a text file and read them back out later on

Unit Convertor

Converts various units between one another.

The user enters the type of unit being entered, the type of unit they want to convert to and then the value.

The program will then make the conversion.

Count Vowels

Enter a string and the program counts the number of vowels in the text. For added complexity have it report a sum of each vowel found.

Password Reset Program

Only accept a new password if it is:

  1. At least eight characters long
  2. Cannot be all text or all numbers or all symbols

The password reset program should also make the user input their new password twice so that the computer knows that the user has not made any mistakes when typing their new password.

Extensions:

  1. Make some sort of algorithm to suggest how strong the password is (Weak, Medium, Strong) depending on length, whether or not the password has special characters in etc
  2. Let the user input their username. The program should go to a text file with a list of usernames and old passwords, and the program should only let you change your password if
    you input your old password.

Email Validator

Make a program to check whether an email address is valid or not.
For instance, you could make sure that there are no spaces, that there is an @ symbol and a dot somewhere after it. Also check the length of the parts at the start, and that the end parts
of the address are not blank.

Extensions:

  1. When an email address is found to be invalid, tell the user exactly what they did wrong with their email address rather than just saying it is invalid
  2. Allow the user to choose to give a text file with a list of email addresses and have it process them all automatically

Mastermind

Generate a random four digit number.

The player has to keep inputting four digit numbers until they guess the randomly generated number.

After each unsuccessful try it should say how many numbers they got correct, but not which position they got right.

At the end of the game should congratulate the user and say how many tries it took.

Extensions:

  1. Let the user pick an easy mode which shows the user which position that they guessed correctly
  2. Let the user pick a hard mode that gives five digits instead of four
  3. After the game is finished, ask the user for their name and input their score into a table. Show them the high score at the start of the game so that it gives a sense of competition

Basic Lists

Make a program that lets a user input a series of names into a list. The program should then ask the user whether they want to print out the list in the original order, or in reverse.

Extensions:

  1. Enable the user to choose what number item in the list they want to print out
  2. Enable the user to only print out a ‘slice’ of the list (eg item three to item nine only)
  3. Enable the user to remove any items of the list that they want to
  4. Enable the user to save their list to a file for later, and also enable them to load it back up again too
  5. ‘Clean’ the list by making all the items lowercase.

Max and Min List

Write a program that lets the user input a list of numbers. Every time they input a new number, the program should give a message about what the maximum and minimum numbers
in the list are.

Extensions

  1. The program should let the user choose the allowable minimum and maximum values, and should not let the user input something to the list that is outside of these bounds
  2. The user should be able to write these values to a file and then also read them back out again.
  3. If a file has any numbers outside of the boundaries, it should strip them out of the list once it has read them in

Letter List

Write a program that lets a user choose a letter. The program will then find all the words beginning with that letter in a list and print them out. It should also say how many words it found.

Extensions:

  1. Let the user load up a list of words from a file and have the program process them all
  2. Change the program so that the user can choose whether they want all words with only the start of the letter, or ANY place in the word

RPG Character Creator

RPG character/Pokemon stat creator
Make a program which will randomly create a character’s stats based on several rules set by the user. Have it generate a class, gender, strength/magic/dexterity points, and extra abilities
or trades. Have the program save it to a file which can then be printed out so that it can be used in a game.

Extension:

  1. Make a mystical name generator. Perhaps randomise different name parts such as sha-ra-lam or big-lim-con to create names for each of your randomly generated characters.

Shopping List

Create a program that will keep track of items for a shopping list. The program should allow you to keep adding new items. You should also be able to record which shop you are going to visit for the item.

Extensions:

  1. Extend the program to record what priority the item is
  2. Extend the program to record whether or not you have bought the item or not
  3. Extend the program to say how much you are willing to pay for each item
  4. Extend the program to say the quantity needed for each item
  5. Make a part of your program that can give you the approximate total of what you intend to spend on your shopping trip. Make sure that you take into account whether you have
    already bought the item or not (ie don’t add this up!).