Challenges 🏆

On this page you will find several challenges you can complete if you want some practice creating scripts and programs with Python. Since there are many ways to approach a problem with computer science note that some solutions may be different that yours but that does not mean that one is better than the other.

In this challenge you will take a float that represents a degree in Celsius and convert it to Fahrenheit. The formula to convert C to F is: (x°C * 9/5) + 32. Below is an example of what it will look like:

Input: 123.5
Output: 254.3

input = 123.5

output = (input * (9/5)) + 32

print(output)

In this challenge you will take a list of integers and sort them from smallest to greatest without the use of any sorting functions. Below is an example of what it will look like:

Input: [100, 3002, 1, 0, -13, 98]
Output: [-13, 0, 1, 98, 100, 3002]

input = [100, 3002, 1, 0, -13, 98]
output = []

while input:
    min = input[0]
    for i in input:
        if i < min:
            min = i
    output.append(min)
    input.remove(min)

print(output)

In this challenge you will create a simple to-do list application that allows you to add things that need to be done and remove them. Below is an example of what it will look like:

----- to-do list -----

--- commands ---
1 - to add
2 - to remove
3 - to quit
type a command: 1
type the event to add to the to-do list: go for a run
----- to-do list -----
1 - go for a run

--- commands ---
1 - to add
2 - to remove
3 - to quit
type a command: 1
type the event to add to the to-do list: do homework 
----- to-do list -----
1 - go for a run
2 - do homework

--- commands ---
1 - to add
2 - to remove
3 - to quit
type a command: 2
type number of event you wish to remove: 1
----- to-do list -----
1 - do homework

--- commands ---
1 - to add
2 - to remove
3 - to quit
type a command: 3
goodbye

to_do_list = []

exit = False

while not exit:
    to_do_string = ""
    for i in range(0, len(to_do_list)):
        to_do_string += str(i + 1) + " - " + to_do_list[i] + "
"

    print("----- to-do list -----")
    print(to_do_string)
    print("--- commands ---")
    print("1 - to add")
    print("2 - to remove")
    print("3 - to quit")

    command = input("type a command: ")

    if command == "1":
        event = input("type the event to add to the to-do list: ")
        to_do_list.append(event)
    elif command == "2":
        num = int(input("type number of event you wish to remove: "))
        to_do_list.pop(num - 1)
    elif command == "3":
        print("goodbye")
        exit = True

In this challenge you will crack or find a lowercase word by randomly generating strings and seeing if they match and how many tries it took. Warning, watch out for infinite loops and trying to find long strings will take awhile. Below is an example of what it will look like:

Input: hi
Output: The string "hi" took 1263 tries

from random import randint

input ="hi"

abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
found = False

tries = 0
while not found:
    attempt = ""
    for i in range(0, len(input)):
        attempt += abc[randint(0, len(abc) - 1)]
    
    print(attempt)
    tries = tries + 1
    
    if input == attempt:
        found = True

print("The string \"" + input + "\" took " + str(tries) + " tries")

In this challenge you will create a tic tac toe game. Below is an example of what it will look like:

key:
7 8 9
4 5 6
3 2 1


_ _ _
_ _ _
_ _ _
it's your turn X
where do you want to move
1


_ _ _
_ _ _
_ _ X
it's your turn O
where do you want to move
2


_ _ _
_ _ _
_ O X
it's your turn X
where do you want to move
4


_ _ _
X _ _
_ O X
it's your turn O
where do you want to move
2
that place is already filled, please make a move somewhere else


_ _ _
X _ _
_ O X
it's your turn X
where do you want to move
5


_ _ _
X X _
_ O X
it's your turn O
where do you want to move
6


_ _ _
X X O
_ O X
it's your turn X
where do you want to move
7


X _ _
X X O
_ O X

game over

 --- X won ---

board = {7: "_", 8: "_", 9: "_",
         4: "_", 5: "_", 6: "_",
         3: "_", 2: "_", 1: "_",}

def print_board():
    print("\n")
    print(board[7] + " " + board[8] + " " + board[9])
    print(board[4] + " " + board[5] + " " + board[6])
    print(board[3] + " " + board[2] + " " + board[1])

print("key:")
print("7 8 9")
print("4 5 6")
print("3 2 1")

turn = "X"
count = 0

for i in range(10):
    print_board()
    print("it's your turn " + turn + "
where do you want to move")

    move = int(input())
    if board[move] == "_":
            board[move] = turn
            count += 1
    else:
        print("that place is already filled, please make a move somewhere else")
    
    if count >= 5:
        if board[7] == board[8] == board[9] != "_":
            print_board()
            print("\ngame over\n")                
            print(" --- " + turn + " won ---")                
            break
        elif board[4] == board[5] == board[6] != "_":
            print_board()
            print("\ngame over\n")                
            print(" --- " + turn + " won ---")
            break
        elif board[1] == board[2] == board[3] != "_":
            print_board()
            print("\ngame over\n")                
            print(" --- " + turn + " won ---")
            break
        elif board[1] == board[4] == board[7] != "_":
            print_board()
            print("\ngame over\n")                
            print(" --- " + turn + " won ---")
            break
        elif board[2] == board[5] == board[8] != "_":
            print_board()
            print("\ngame over\n")                
            print(" --- " + turn + " won ---")
            break
        elif board[3] == board[6] == board[9] != "_":
            print_board()
            print("\ngame over\n")                
            print(" --- " + turn + " won ---")
            break 
        elif board[7] == board[5] == board[3] != "_":
            print_board()
            print("\ngame over\n")                
            print(" --- " + turn + " won ---")
            break
        elif board[1] == board[5] == board[9] != "_":
            print_board()
            print("\ngame over\n")                
            print(" --- " + turn + " won ---")
            break 

        if count == 9:
            print("\ngame over\n")                
            print("it's a tie")

    if turn =='X':
        turn = 'O'
    else:
        turn = 'X'