Day -3 Project:
print('''
***********************************************************************
********
||||
_________|________________.=""_;=.______________|_____________________|
_______
| | ,-"_,="" `"=.| |
|___________________|__"=._o`"-._ `"=.______________|___________________
| `"=._o`"=._ _`"=._ |
_________|_____________________:=._o "=._."_.-="'"=.__________________|
_______
| | __.--" , ; `"=._o." ,-"""-._ ". |
|___________________|_._" ,. .` ` `` , `"-._"-._ ". '__|___________________
| |o`"=._` , "` `; .". , "-._"-._; ; |
_________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
| | |o; `"-.o`"=._`` '` " ,__.--o; |
|___________________|_| ; (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._ " `".o|o_.--" ;o;____/______/______/____
/______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/
____
/______/______/______/______/______/______/______/______/______/______/_____
/
***********************************************************************
********
''')
print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.")
way=input("Which way does you want to go? left or right:")
if way=="left":
wait=input("You swim or wait for boat ? s,w")
if wait=="w":
door=input("which do want to choose ?:red ,blue or yellow")
if door=="red":
print("Burned bny a fire Game Over")
if door=="blue":
print("Eaten by a Beast Game Over")
else:
print("***YOU WIN***")
else:
print("You Dead Game Over")
else:
print("Fall into the Hole Game Over")
Flow chart:
Day-4: Stone , Paper , Scissors ,Game:
import random
rock = '''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
'''
paper = '''
_______
---' ____)____
______)
_______)
_______)
---.__________)
'''
scissors = '''
_______
---' ____)____
______)
__________)
(____)
---.__(___)
'''
game_image=[rock,paper,scissors]
user_choice=int(input(" What is your choice ? : type 0
for rock , type for paper , and type 2 for scissors : "))
if user_choice >3 or user_choice<0:
print("😰**You type the invalid Number**😰 ,'GAME
OVER'")
else:
print(game_image[user_choice])
computer_choice = [Link](0,2)
print("computer choice")
print(game_image[computer_choice])
if user_choice == 0 and computer_choice == 2:
print("😉**You win**😉")
elif user_choice == 2 and computer_choice == 0:
print("😞**You lose**😞")
elif user_choice < computer_choice:
print("😞**You lose**😞")
elif user_choice>computer_choice:
print("😉**You win**😉")
elif user_choice == computer_choice:
print("😇**Its Draw**😇")
Day:5 - Password Generator Project
import random
letters = ['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', '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']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like
in your password?\n"))
nr_symbols = int(input(f"How many symbols would you
like?\n"))
nr_numbers = int(input(f"How many numbers would you
like?\n"))
password =[]
for char in range (1,nr_letters + 1):
random_char=[Link](letters)
password +=random_char
for chars in range (1,nr_symbols+1):
random_char=[Link](symbols)
password +=random_char
for chars in range (1,nr_numbers+1):
random_char=[Link](numbers)
password +=random_char
[Link](password)
new_password = ""
for char1 in password:
new_password += char1
print(f"Your Passwor is:{new_password}")
Day-6: Robot Correct path
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()
Day-7:Hangman Game
from replit import clear
import random
from hangman_words import word_list
chosen_word = [Link](word_list)
word_length = len(chosen_word)
end_of_game = False
lives = 6
from hangman_art import logo
print(logo)
#Testing code
print(f'Pssst, the solution is {chosen_word}.')
#Create blanks
display = []
for _ in range(word_length):
display += "_"
while not end_of_game:
guess = input("Guess a letter: ").lower()
clear()
if guess in display:
print(f"You've already guessed {guess}")
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
#Check if user is wrong.
if guess not in chosen_word:
print(f"You guessed {guess}, that's not in the word. You
lose a life.")
lives -= 1
if lives == 0:
end_of_game = True
print("You lose.")
print(f"{' '.join(display)}")
if "_" not in display:
end_of_game = True
print("You win.")
from hangman_art import stages
print(stages[lives])
Day : 8 – caesar cipher:
from art import logo
print(logo)
alphabet = ['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', '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']
def caesar(start_text, shift_amount, cipher_direction):
end_text = ""
if cipher_direction == "decode":
shift_amount *= -1
for char in start_text:
if char in alphabet:
position = [Link](char)
new_position = position + shift_amount
end_text += alphabet[new_position]
else:
end_text += char
print(f"Here's the {cipher_direction}d result: {end_text}")
should_continue = True
while should_continue :
direction = input("Type 'encode' to encrypt, type 'decode'
to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
shift = shift%26
caesar(start_text=text, shift_amount=shift,
cipher_direction=direction)
exit_continue = input("Type 'yes' if you want to go
again. Otherwise type 'no'").lower()
if exit_continue == "no":
should_continue = False
print("👋 Good Bye 👋")
Day - 9 secret Bids :
Flow chart:
from replit import clear
from art import logo
print(logo)
bids = {}
bidding_finished = False
def find_highest_bidder(bidding_record):
highest_bid = 0
winner = ""
for bidder in bidding_record:
bid_amount = bidding_record[bidder]
if bid_amount > highest_bid:
highest_bid = bid_amount
winner = bidder
print(f"The winner is {winner} with a bid of $
{highest_bid}")
while not bidding_finished:
name = input("What is your name?: ")
price = int(input("What is your bid?: $"))
bids[name] = price
should_continue = input("Are there any other bidders?
Type 'yes or 'no'.\n")
if should_continue == "no":
bidding_finished = True
find_highest_bidder(bids)
elif should_continue == "yes":
clear()
Day : 10 – Calculator:
from art import logo
from replit import clear
#calculator
#add
def add(n1,n2):
return n1 + n2
def sub(n1,n2):
return n1-n2
def mul (n1,n2):
return n1*n2
def div(n1,n2):
return n1/n2
dic = {
"+": add,
"-": sub,
"*": mul,
"/": div
}
def calculator():
print(logo)
num1 = float(input("Enter the First Number : "))
for operation in dic:
print(operation)
a = True
while a :
operation_symbols = input("Select Which Operation Does
You Needed : ")
num2 = float(input("Enter the second Number : "))
calculation_function = dic[operation_symbols]
answer = calculation_function (num1,num2)
print(f"{num1} {operation_symbols} {num2} : {answer}")
continue_cal = input(f"Type 'y' to continue_calculation
with {answer} or Type 'n' for new Calculator or Type 0
for exit:").lower()
if continue_cal == "y":
num1 = answer
elif continue_cal == "n" :
clear()
calculator()
else:
a = False
print(f"{num1} {operation_symbols} {num2} : {answer}")
print("Good Bye")
calculator()
Day- 12 Number Guessing Project :
from random import randint
from art import logo
EASY_LEVEL_TURNS = 10
HARD_LEVEL_TURNS = 5
#Function to check user's guess against actual answer.
def check_answer(guess, answer, turns):
"""checks answer against guess. Returns the number of turns remaining."""
if guess > answer:
print("Too high.")
return turns - 1
elif guess < answer:
print("Too low.")
return turns - 1
else:
print(f"You got it! The answer was {answer}.")
#Make function to set difficulty.
def set_difficulty():
level = input("Choose a difficulty. Type 'easy' or 'hard': ")
if level == "easy":
return EASY_LEVEL_TURNS
else:
return HARD_LEVEL_TURNS
def game():
print(logo)
#Choosing a random number between 1 and 100.
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
answer = randint(1, 100)
print(f"Pssst, the correct answer is {answer}")
turns = set_difficulty()
#Repeat the guessing functionality if they get it wrong.
guess = 0
while guess != answer:
print(f"You have {turns} attempts remaining to guess the number.")
#Let the user guess a number.
guess = int(input("Make a guess: "))
#Track the number of turns and reduce by 1 if they get it wrong.
turns = check_answer(guess, answer, turns)
if turns == 0:
print("You've run out of guesses, you lose.")
return
elif guess != answer:
print("Guess again.")
game()
Day – 18 Hirst Painting:
# import colorgram
#
# rgb_color = []
#
# colors = [Link]('[Link]', 30)
# for color in colors:
# r = [Link].r
# g = [Link].g
# b = [Link].b
# new_Color = (r, g, b)
# rgb_color.append(new_Color)
#
# print(rgb_color)
import turtle
import turtle as turtle_module
import random
turtle_module.colormode(255)
tim = turtle_module .Turtle()
[Link]()
[Link]()
color_list = [(1, 9, 29), (122, 95, 41), (238, 211, 73),
(77, 34, 23), (221, 80, 59), (225, 117, 100), (92, 1, 21),
(179, 139, 170), (151, 92, 116), (35, 90, 26), (8, 154,
72), (205, 64, 92), (220, 177, 219), (167, 129, 75), (1,
63, 146), (3, 80, 30), (4, 220, 217), (80, 134, 178), (77,
115, 147), (129, 157, 178), (123, 185, 166), (124, 8, 30),
(12, 213, 221), (245, 203, 5), (134, 221, 207), (229, 174,
167)]
[Link](225)
[Link](300)
[Link](0)
number_of_dots = 100
for dots_count in range(1, number_of_dots + 1):
[Link](20, [Link](color_list))
[Link](50)
if dots_count % 10 == 0:
[Link](90)
[Link](50)
[Link](180)
[Link](500)
[Link](0)
screen = turtle_module.Screen()
[Link]()
Day-19 “Turtle Race”:
from turtle import Turtle, Screen
import random
is_on = False
screen = Screen()
[Link](width=500, height=400)
user_bets = [Link](title="Make Your bet",
prompt="Which Turtle Will WIN the race? Enter The
color: ")
colors = ["red", "black", "green", "blue", "orange",
"pink"]
y_position = [-70, -40, -10, 20, 50, 80]
all_turtle = []
for _ in range(0, 6):
new_turtle = Turtle(shape="turtle")
new_turtle.color(colors[_])
new_turtle.penup()
new_turtle.goto(x=-230, y=y_position[_])
all_turtle.append(new_turtle)
if user_bets:
is_on = True
while is_on:
for turtle in all_turtle:
if [Link]() >= 230:
is_on = False
winning_color = [Link]()
if winning_color == user_bets:
print(f" You WIN. he {winning_color}
turtle is the winner!")
else:
print(f"You've lost! The {winning_color}
turtle is the winner!")
rand_distance = [Link](0, 10)
[Link](rand_distance)
[Link]()
Day 20-21 : Snake Game :
[Link]
# Step To tactile Snake Game:
# 1. Create A snake Box
# 2. Move The Snake
# [Link] A Snake Food
# [Link] The collision with the food
# [Link] A scoreboard
# [Link] the collision in the Wall
# [Link] the collision in the Tails
from turtle import Screen
import time
from snake import Snake
from food import Food
from scoreboard import Scoreboard
screen = Screen()
[Link](width=600, height=600)
[Link]("black")
[Link]("My Snake Game")
[Link](0)
snake = Snake()
food = Food()
scoreboard = Scoreboard()
[Link]()
[Link]([Link], "Up")
[Link]([Link], "Down")
[Link]([Link], "Left")
[Link]([Link], "Right")
game_is_on = True
while game_is_on:
[Link]()
[Link](0.1)
[Link]()
# Detect collision with the Food.
if [Link](food) < 20:
[Link]()
[Link]()
scoreboard.increase_score()
# Detect collision with the Wall.
if [Link]() > 280 or [Link]() < -
280 or [Link]() > 280 or [Link]() < -
280:
game_is_on = False
[Link]()
for segment in [Link][1:]:
if [Link](segment) < 10 :
game_is_on = False
[Link]()
[Link]()
from turtle import Turtle
import random
class Food(Turtle):
def __init__(self):
super().__init__()
[Link]("circle")
[Link]("blue")
[Link]()
[Link]("fastest")
[Link](stretch_wid=0.5, stretch_len=0.5)
random_x = [Link](-280, 280)
random_y = [Link](-280, 280)
[Link](x=random_x, y=random_y)
[Link]:
from turtle import Turtle
STARTING_POSITION = [(0, 0), (-20, 0), (-40, 0)]
MOVE_DISTANCE = 20
UP = 90
DOWN = 270
LEFT = 180
RIGHT = 0
class Snake:
def __init__(self):
[Link] = []
self.create_snake()
[Link] = [Link][0]
def create_snake(self):
for position in STARTING_POSITION:
self.add_segment(position)
def add_segment(self, position):
new_segment = Turtle("square")
new_segment.color("white")
new_segment.penup()
new_segment.goto(position)
[Link](new_segment)
# add a element to snake
def extend(self):
self.add_segment([Link][-1].position())
def move(self):
# Start = (len(segments)-1)
# stop = 0
# step = -1
for seg_num in range(len([Link]) - 1, 0, -
1):
new_x = [Link][seg_num - 1].xcor()
new_y = [Link][seg_num - 1].ycor()
[Link][seg_num].goto(new_x, new_y)
[Link](MOVE_DISTANCE)
def up(self):
if [Link]() != DOWN:
[Link](UP)
def down(self):
if [Link]() != UP:
[Link](DOWN)
def left(self):
if [Link]() != RIGHT:
[Link](LEFT)
def right(self):
if [Link]() != LEFT:
[Link](RIGHT)
[Link]:
from turtle import Turtle
import random
class Food(Turtle):
def __init__(self):
super().__init__()
[Link]("circle")
[Link]()
[Link](stretch_len=0.5, stretch_wid=0.5)
[Link]("blue")
[Link]("fastest")
[Link]()
def refresh(self):
random_x = [Link](-280, 280)
random_y = [Link](-280, 280)
[Link](random_x, random_y)
Score_Board.py:
from turtle import Turtle
ALIGNMENT = "center"
FONTS = ("Arial", 24, "normal")
class Scoreboard(Turtle):
def __init__(self):
super().__init__()
[Link] = 0
[Link]("white")
[Link]()
[Link](0, 260)
[Link]()
self.update_scoreboard()
def update_scoreboard(self):
[Link](f"Score : {[Link]}",
align=ALIGNMENT, font=FONTS)
def increase_score(self):
[Link]()
[Link] += 1
self.update_scoreboard()
def gameover(self):
[Link](0, 0)
[Link]("Game Over", align=ALIGNMENT,
font=FONTS)