Posts

Paint Area Calculator

Image
You are painting a wall. The instructions on the paint can say that **1 can of paint can cover 5 square meters** of the wall. Given a random height and width of wall, calculate how many cans of paint you'll need to buy. the number of cans = (wall height ✖️ wall width) ÷ coverage per can.  But because you can't buy 0.6 of a can of paint, the **result should be rounded up** to **2** cans.  import math def paint_calc(height, width, cover): print(f"You need {math.ceil((height*width)/coverage)} cans") test_h = int(input("Height of wall: ")) test_w = int(input("Width of wall: ")) coverage = 5 paint_calc(height=test_h, width=test_w, cover=coverage)

Hangman - 3 other versions (advanced)

Image
  #Step 4 import random stages = [''' +---+ | | O | /|\ | / \ | | ========= ''', ''' +---+ | | O | /|\ | / | | ========= ''', ''' +---+ | | O | /|\ | | | ========= ''', ''' +---+ | | O | /| | | | =========''', ''' +---+ | | O | | | | | ========= ''', ''' +---+ | | O | | | | ========= ''', ''' +---+ | | | | | | ========= '''] end_of_game = False word_list = ["aardvark", "baboon", "camel", "flower", "singapore", "alex" ] chosen_word = random.choice(word_list) word_length = len(chosen_word) #TODO-1: - Create a variable called 'lives' to keep track of the number of lives left. #Set ...

Hangman - 3 versions

Image
#very simple code - V1 import random word_list = ["aardvark", "baboon", "camel", "myblog", "abs"] chosen_word = random.choice(word_list) guess = input("Guess a letter? >> ").lower() for letter in chosen_word: if letter == guess: print("Right!") else: print("Wrong!")   #much more advanced code - V2 import random word_list = ["aardvark", "baboon", "camel"] chosen_word = random.choice(word_list) #Testing code print(f'Pssst, the solution is {chosen_word}.') display = [] word_length = len(chosen_word) for _ in range(word_length): display += "_" guess = input("Guess a letter: ").lower() for position in range(word_length): letter = chosen_word[position] #print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}") if letter == guess: display[position] = letter print(display...

Escaping the Maze - Reeborg's world

Image
 def turn_right():     turn_left()     turn_left()     turn_left() while not at_goal():      if right_is_clear():         turn_right()         move()     elif front_is_clear():         move()     else:         turn_left() This code is not complete yet, will get back to it after day 15th.           

The hurdle loop challenge 3 - using "variable Hurdle" - Reeborg's world

Image
def turn_right():     turn_left()     turn_left()     turn_left()   def jump_long():     turn_left()     while wall_on_right():         move()     turn_right()     move()     turn_right()     while front_is_clear():         move()     turn_left()  while not at_goal():     if wall_in_front():         jump_long()     else:         move()  

The hurdle loop challenge 3 - using "while loops" - Reeborg's world

Image
 def turn_right():     turn_left()     turn_left()     turn_left() def jump():     turn_left()     move()     turn_right()     move()     turn_right()     move()     turn_left()   while not at_goal():     if wall_in_front():         jump()     else:         move()            

The hurdle loop challenge 2 - Moving hurdle - using "while loops" - Reeborg's world

Image
def turn_right():     turn_left()     turn_left()     turn_left() def jump():     move()     turn_left()     move()     turn_right()     move()     turn_right()     move()     turn_left() number_of_hurdles = 6 while number_of_hurdles > 0:     if at_goal():         pause()        else:         jump()         number_of_hurdles -= 1         print(number_of_hurdles) A simpler way to write this code would be: def turn_right():     turn_left()     turn_left()     turn_left() def jump():     move()     turn_left()     move()     turn_right()     move()     turn_right()     move()     turn_left()   while not at_goal():     jump() And we will get the sam...