Here are some example problems to solve! They are listed roughly by how hard they will be to solve, top to bottom (easiest at the top).
This isn't a challenge, just something that is used in a number of the other challenges. How to create a random number:
# Allows us to use a function someone else wrote (called "randint") from random import randint # Selects a number anywhere between 6 and 12 (including 6 and 12) my_var = randint(6, 12)
Dice Rolling Simulator
When the program runs, it will randomly choose a number between 1 and 6. (Or whatever other integer you prefer — the number of sides on the die is up to you.) The program will print what that number is. It should then ask you if you’d like to roll again.
Flips a coin! (Hint, you'll need to use the
randint function here too)
Have the user enter an price, and the amount of cash the customer has given, and have it calculate the change (could put this in a loop so you don't have to run the program many many times).
You could also add sales tax, so that the user inputs a subtotal (total without tax), and the program calcuates the tax as well.
When the program runs, it will prompt the user for a length and width, and then calculate the area of the resulting rectangle. You can expand this program to include multiple shapes, or multiple measurments (things like perimeter)
You could also have a user input the area of a floor space that needs to be covered with tile, and given the size of a single tile, make the program calculate how much tile is needed to cover the floor (could also be adapted to carpet, or even volume, aka, the amount of dirt needed to make a layer that is a certain depth over a specified area)
A Fibonacci sequence is a series of numbers that are the sum of the previous two numbers of the sequence. For example:
1, 1, 2, 3, 5, 8, 13 is a fibonacci sequence, since 1 + 1 = 2, and 1 + 2 = 3, and so on.
Create a program that generates a certain number of fibbonacci numbers (inputted by the user of course!). Alternatively, you could generate a fibonacci sequence based off of a user-inputted number (for example, input 4, and build this sequence:
4, 4, 8, 12, 20 etc.)
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
Guess the Number
The program will first randomly generate a number unknown to the user. The user needs to guess what that number is. (In other words, the user needs to be able to input information.) If the user’s guess is wrong, the program should return some sort of indication as to how wrong (e.g. The number is too high or too low). If the user guesses correctly, a positive indication should appear (And the program should exit).
You can use functions to check if the user input is an actual number, to see the difference between the inputted number and the randomly generated numbers, and to then compare the numbers.
exit() function can be used to quit the program.
Guess the Word - Hard!
The program will need a user to input a single letter guess and if the letter is in the word, then give some indication of that. This game is similar to hangman, but instead of a hangman you can use a counter someplace in your program.
Hint, You'll need something called a
for loop. One of your room instructors can tell you about them.