0% found this document useful (0 votes)
224 views

Python Code Files Assignment

The document contains code examples for various Python programs and exercises, including: - A band name generator that takes a city and pet name as input to output a band name. - Examples demonstrating data types, BMI calculator, age calculator, tip calculator, conditional statements like if/else, nested if/else, functions, loops, and simple games like rock paper scissors. - The code provides comments to explain the program logic and outputs the results for sample user inputs. The code samples serve as learning tools for Python basics like data types, conditional logic, functions, loops, taking user input, and building simple text-based programs and games.

Uploaded by

pavan wanjari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
224 views

Python Code Files Assignment

The document contains code examples for various Python programs and exercises, including: - A band name generator that takes a city and pet name as input to output a band name. - Examples demonstrating data types, BMI calculator, age calculator, tip calculator, conditional statements like if/else, nested if/else, functions, loops, and simple games like rock paper scissors. - The code provides comments to explain the program logic and outputs the results for sample user inputs. The code samples serve as learning tools for Python basics like data types, conditional logic, functions, loops, taking user input, and building simple text-based programs and games.

Uploaded by

pavan wanjari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

Python code files Assignment code

BAND NAME GENERATOR


print("Welcome to the Band Name Generator.")
print("what's name of the city you grew up
in?")
a=input("")
name_city=a
print("what's your pet's name? ")
b=input("")
name_pet=b
print("Your band name could be " + "" +
name_city + " " + name_pet )
OUTPUT
Welcome to the Band Name Generator.
what's name of the city you grew up in?
NAGPUR
what's your pet's name?
TOMMY
Your band name could be NAGPUR TOMMY

Subscript Code Example


street_name = "Abbey Road"
print(street_name[4] + street_name[7])
out put = yR (bcz of two spaces in between Abbey & Road)
DATA TYPES EXAMPLES
# 🚨 Don't change the code below 👇
two_digit_number = input("Type a two digit
number: ")
# 🚨 Don't change the code above 👆

####################################
#Write your code below this line 👇

#Check the data type of two_digit_number


# print(type(two_digit_number))

#Get the first and second digits using


subscripting then convert string to int.
first_digit = int(two_digit_number[0])
second_digit = int(two_digit_number[1])

#Add the two digits togeter


two_digit_number = first_digit + second_digit

print(two_digit_number)
OUTPUT

INPUT = 55

OUTPUT = 5 + 5 =10

BMI CALCULATOR CODE


 🚨 Don't change the code below 👇
height = input("enter your height in m: ")
weight = input("enter your weight in kg: ")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇

ht = float(height)
wt = int(weight)
#print(type(ht))
#print(type(wt))

BMI = (wt / (ht * ht))

BMI_float = int(BMI)

print(BMI_float)
OUTPUT
INPUT: HEIGHT = 1.75m & WEIGHT = 80 kg

OUTPUT = 26

REMAINING AGE CALCULATOR


# 🚨 Don't change the code below 👇
age = input("What is your current age?")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇

CurrentAge= int(age)

RemaningAge= 90-CurrentAge

#print(RemaningAge)

RemainingDays = (RemaningAge*365)
#print(RemainingDays)

RemainingWeeks = int(RemaningAge * 52)

RemainingMonths = int(RemaningAge * 12)

print(f"You have {RemainingDays} days, {Remai
ningWeeks} weeks, and {RemainingMonths} month
s left.")
OUTPUT
INPUT : What is your Age? 31
OUTPUT : You have 12410 days, 1768 weeks, and 408 months left
HOTEL TIP CALCULATOR
print("Welcome to the tip calcultor")
Totalbill=input("What was the total bill? ")
TotalTip=input("How much tip would you like
to give? 10, 12, or 15? ")
TotalPpl=input("How many people to slpit the
bill? ")

Finalbill= float(Totalbill)
#print(Finalbill)

FinalTip= int(TotalTip)
#print(FinalTip)

NumberofGuest= int(TotalPpl)
#print(NumberofGuest)
FinalScore= (Finalbill * (FinalTip / 100))
#print(FinalScore)

FinalSettlement =round((Finalbill +
FinalScore) / NumberofGuest, 2)

#print(FinalSettlement)

print(f"Eachperson should pay: $


{FinalSettlement}" )
OUTPUT = $19.93 (Input Total bill = $124.56, Tip = 12%, Numberof Guest=7
IF & ELSE CONDITIONAL EXAMPLE CODE
print("Welcome to the Marriage Beureu")
Age= int(input("What is your age? "))

if Age >18:
print("You are eligible for marriage")
else:
print("Please complete your age, now are
not eligible")
OUTPUT:
INPUT = 21 (You are Eligible for Marriage)
INPUT = 17 (Please complete your age, now you are not eligible)

number=int(input("Which no want to check? "))

Numcheck = (number % 2)
if Numcheck <= 0:
    print("This is an even number")
else:
    print("This is an odd number")
OUTPUT:
INPUT = 20 (This is an Even Number)
INPUT = 25 (This is an Odd Number)

NESTED IF / ELIF / ELSE CONDITION


print("Welcome to the RollerCoster.")
Height= int(input("What is your height? "))

if Height > 120:


print("You can take a ride.")
Age= int(input("What is your age? "))
if Age < 12:
print("You have to pay 10$.")
elif Age <=18:
print("You have to pay 15$.")
else:
print("You have to pay 20$.")

else:
print("Sorry, You can grow more.")
OUTPUT:
INPUT = Height 130 (You can take ride)
INPUT = Age 10 (You have to pay 10$)
INPUT = Age 13 (You have to pay 15$)
INPUT = Age 20 (You have to pay 20$)
INPUT = Height 110 (Sorry, You can grow more)
BMI 2.0 CALCULATOR CODE EXAMPLE
Height=float(input("enter ur height in m:"))
weight=float(input("enter ur weight in kg:"))

BMI = round (weight / (height * height))

if BMI < 35:
    if BMI < 18.5:
        print(f"Your BMI is {BMI}, you have u
nder weight")
    elif BMI < 25:
        print(f"Your BMI is {BMI}, you are no
rmal weight")
    elif BMI < 30:
        print(f"Your BMI is {BMI}, you are sl
ightly overweight")
    else:
        print(f"Your BMI is {BMI}, you are ob
ese")
else:
    print(f"Your BMI is {BMI}, you are Clinic
ally obese")
OUTPUT:"Your BMI is 18, you are underweight."

"Your BMI is 22, you have a normal weight."


"Your BMI is 28, you are slightly overweight."
"Your BMI is 33, you are obese."
"Your BMI is 40, you are clinically obese."

LEAP YEAR EXERCISE


year = int(input("Which year do you want to
check? "))

FirstStep= (year % 4)
SecondStep = (year % 100)
ThirdStep = (year % 400)

if FirstStep <=0:
#print("Leap year.")
if SecondStep >=0:
print("Leap year.")
elif ThirdStep <=0:
print("Leap year.")
else:
print("Not leap year.")
else:
print("Not leap year.")
OUTPUT:
INPUT = 2400 (Leap Year) & INPUT = 1989 (Not Leap Year)
MULTIPLE IF CONDITION – ROLLERCOASTER WITH PHOTO
CODE EXERCISE

print("Welcome to the rollercoaster!")


height = int(input("What is your height in
cm? "))
bill = 0

if height >= 120:


print("You can ride the rollercoaster!")
age = int(input("What is your age? "))
if age < 12:
bill = 5
print("Child tickets are $5.")
elif age <= 18:
bill = 7
print("Youth tickets are $7.")
else:
bill = 12
print("Adult tickets are $12.")
wants_photo = input("Do you want a photo
taken? Y or N. ")
if wants_photo == "Y":
bill += 3

print(f"Your final bill is ${bill}")

else:
print("Sorry, you have to grow taller
before you can ride.")
OUTPUT:
INPUT: Height = 130
INPUT: Age = 21
INPUT: Photo = Yes
TOTAL BILL = $15
PIZZA ORDER EXERCISE CODE
print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want? S, 
M, or L ")
add_pepperoni = input("Do you want pepperoni? 
Y or N ")
extra_cheese = input("Do you want extra chees
e? Y or N ")

if size == "S":
    PizzaCost= 15

elif size == "M":
    PizzaCost= 20

else:
    PizzaCost= 25

if add_pepperoni == "Y":
    if size == "S":
        PizzaCost += 2
    else:
        PizzaCost += 3

if extra_cheese == "Y":
        PizzaCost += 1

print(f"Your final bill is: ${PizzaCost}.")
LOVE CALCULATOR EXERCISE CODE – “AND” “OR” CONDITION
IN IF, ELSE
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")

combine_string= name1 + name2
lower_combined_string = combine_string.lower(
)

t = lower_combined_string.count("t")
r = lower_combined_string.count("r")
u = lower_combined_string.count("u")
e = lower_combined_string.count("e")

true = t + r + u + e

l = lower_combined_string.count("l")
o = lower_combined_string.count("o")
v = lower_combined_string.count("v")
e = lower_combined_string.count("e")

love = l + o + v + e

Love_Score = int(str(true) + str(love))
print(Love_Score)

if (Love_Score < 10) or (Love_Score > 90):
    print(f"Your score is {Love_Score}, you g
o together like coke and mentos. ")

elif (Love_Score >= 40) and (Love_Score <= 50
):
    print(f"Your score is {Love_Score}, you a
re alright together. ")
else:
    print(f"Your score is {Love_Score}. ")
OUTPUT:
INPUT: KAYNE WEST & KIM KARDASHANI
OUTPUT = YOUR SCORE IS 42, YOU ARE ALRIGHT TOGETHER.
TREASURE HUNT – EXERCISE CODE

print("Welcome to Treasure Island.")


print("Your mission is to find the
treasure.")

Step =input("Select the way from crossraod,


take right or left? ")

Step_one = Step.lower()

if Step_one == "left":
Step_next =input("Go staright and you will
findout a sea, you can wait or swin? ")

Step_two = Step_next.lower()

if Step_two == "wait":
Step_tisra =input("take a boat to reach
the door, select the door colour red, yellow,
blue? ")

Step_three = Step_tisra.lower()

if Step_three == "yellow":
print("Yes you find the Treasure, You
are the real winner.")

else:
print("you will get kill and Game
Over.")

else:
print("you will drown and Game over.")

else:
print("you can fall into the hole, Game
Over.")

OUTPUT:

INPUT 1 = Left (you will go forward) & Right (You will get kill Game over)
INPUT 2 = Wait (you will go forward) & Swim (You will get kill Game over)
INPUT 3 = Yellow (Winner) & Red and Blue (Loser of the Game and its over)

RANDOM HEAD AND TAILS CHALLENGE EXERCISE


Import random
random_test= random.randint(0,1)
if random_test == 1:
    print("Heads")
else:
    print("Tails")
OUTPUT: Heads or Tails
ROCK, PAPER & SCISSOR – EXERCISE CODE

import random

game_images =[Rock, Paper, Scissors]

Input_value = int(input("What do you choose?


Type 0 for Rock, 1 for Paper & 2 for
Scissors. "))

Human_Value = Input_value

Pc_value = random.randint(0,2)

print(game_images[Human_Value])

print(game_images[Pc_value])

if Human_Value==0 and Pc_value==2:


print("You win")

if Human_Value==1 and Pc_value==0:


print("You win")
if Human_Value==2 and Pc_value==1:
print("You win")

else:
print("You lose")
OUTPUT:
INPUT 1 = HUMAN INPUT (0) & COMPUTER RANDOM (1)
OUTPUT = “You lose” (Bcz Rock cannot beat Scissor which is 0  2)
INPUT 2 = HUMAN INPUT (1) & COMPUTER RANDOM (0)
OUTPUT = “You win” (Bcz Paper can beat Rock which is 1 0)

FOR LOOP EXERCISE – STUDENT HEIGHT AVERAGE


student_heights = input("Input a list of stud
ent heights ").split()
for n in range(0, len(student_heights)):
  student_heights[n] = int(student_heights[n]
)
total_height= 0

for height in student_heights:
    total_height += height
#print(f"The Total height {total_height}.")
    
total_students = 0

for students in student_heights:
    total_students += 1
#print(f"The total students {total_students}"
)

Average_heigt = (total_height / total_student
s)
print(round(Average_heigt))
OUTPUT :
INPUT = 100 200 300 400 100 200
OUTPUT = 650

FOR LOOP EXAMPLE – LARGEST NUMBER IN THE LIST

# 🚨 Don't change the code below 👇
student_scores = input("Input a list of stude
nt scores ").split()
for n in range(0, len(student_scores)):
  student_scores[n] = int(student_scores[n])
print(student_scores)
# 🚨 Don't change the code above 👆
#Write your code below this row 👇

largest= student_scores[n]

for large in student_scores:
    if large > largest:
        largest = large

print(f"The highest score in the class is: {l
argest}")
OUTPUT:
INPUT = 54 75 62 84 97 23 14
OUTPUT = THE HIGHEST NUMBER IS 91
(WE CAN SOLVE THIS PROBLEM USING MAX() FUNCTION ALSO BUT
WE SOLVE THIS WITH DIFFERENT METHOD)

FOR LOOP – SUM OF ALL EVEN NUMBER IN RANGE (1, 100)


EXERCISE

even_number = 0

for numbers in range(2,101, 2):
    even_number += numbers

    #print(numbers)
print(even_number)

OUTPUT: 2550

2 + 4 + 6 + 8 + 10 + 12 ……………+ 96 + 98 + 100
FIZZ BUZZ EXERCISE CODE IN FOR LOOP
#Welcome to FizzBuzz Program code 

for numbers in range (1,101):

    if numbers % 3 == 0 and numbers % 5 == 0:
        print("FizzBuzz")

    elif numbers % 3 == 0:
        print("Fizz")

    elif numbers % 5 == 0:
        print("Buzz")

    else:
        print(numbers)
        
OUTPUT:
1
2
FIZZ
4
BUZZ
.
.
13
FIZZBUZZ
PASSWORD GENERATOR PROJECT

#Password Generator Project

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"))

#START CODE FROM BELOW


import random
pass_lett= []
for pass_letter in range(0, nr_letters+1):
pass_lett.append(random.choice(letters))

for pass_number in range(0,nr_numbers+1):


pass_lett += random.choice(numbers)

for pass_symbol in range(0,nr_symbols+1):


pass_lett += random.choice(symbols)

random.shuffle(pass_lett)
print(pass_lett)

finalword = ""
for finalpassword in pass_lett:
finalword += finalpassword
print(finalword)
OUTPUT:
INPUT 1 = HOW MANY ALPHABETS YOU WANT = 5
INPUT 2 = HOW MANY NUMBERS YOU WANT = 2
INPUT 3 = HOW MANY SYMBOLS YOU WANT = 2

OUTPUT = a#kj2MR8@

HURDLE LOOP GAME – (FOR LOOP / WHILE LOOP)


ANOTHER METHOD TO USE THE CODE
While Not at_goal():
Jump()

NEXT LEVEL HURDLE-3


HURDLE – 4 NEXT LEVEL (USE OF IF & WHILE LOOP)
MAZE RUNNER GAME – HARD GAME EXERCISE MUST TRY
HANGMAN GAME EXERCISE

#Step 4
import random

stages = ['''
+---+
| |
O |
/|\ |
/ \ |
|
=========
''', '''
+---+
| |
O |
/|\ |
/ |
|
=========
''', '''
+---+
| |
O |
/|\ |
|
|
=========
''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========
''', '''
+---+
| |
O |
|
|
|
=========
''', '''
+---+
| |
|
|
|
|
=========
''']

end_of_game = False
word_list = ["ardvark", "baboon", "camel"]
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
lives = 7

#TODO-1: - Create a variable called 'lives'


to keep track of the number of lives left.
#Set 'lives' to equal 6.

#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()

#Check guessed letter


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

if guess not in chosen_word:


lives -= 1
if lives == 0:
end_of_game = True
print("You lose")

print(f"{' '.join(display)}")

#Check if user has got all letters.


if "_" not in display:
end_of_game = True
print("You win.")

#TODO-3: - print the ASCII art from


'stages' that corresponds to the current
number of 'lives' the user has remaining.
print(stages[lives])

HANGMAN FINAL VERSION WITH IMPORT FILES

#Step 5
import random
import hangman_words
import hangman_art

#TODO-1: - Update the word list to use the


'word_list' from hangman_words.py
#Delete this line: word_list = ["ardvark",
"baboon", "camel"]
chosen_word =
random.choice(hangman_words.word_list)
word_length = len(chosen_word)

end_of_game = False
lives = 6

#TODO-3: - Import the logo from


hangman_art.py and print it at the start of
the game.
print(hangman_art.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()

if guess in display:
print(f"You have already guess {guess}.
")

for position in range(word_length):


letter = chosen_word[position]
if letter == guess:
display[position] = letter

#Check if user is wrong.


if guess not in chosen_word:
lives -= 1
print(f"You guessed {guess}, that's not
in the word. You lose a life. ")
if lives == 0:
end_of_game = True
print("You lose.")
print(hangman_art.stages[lives])

print(f"{' '.join(display)}")

#Check if user has got all letters.


if "_" not in display:
end_of_game = True
print("You win.")
DEFINE FUNCTION EXERCISE WITH INPUTS
def paint_calc(height,width,cover):
    Number_of_cans = round((height*width)/
cover)
    print(Number_of_cans)

#Write your code above this line 👆
# Define a function called paint_calc() so th
at the code below works.   

# 🚨 Don't change the code below 👇
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)
OUTPUT:
INPUT = Height of the wall = 2 & Width of the wall = 5
OUTPUT = 1.6 or 2 after rounding off

CIPHER CODE ENCODE & DECODE EXERCISE

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']
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"))

def encrypt(plain_text, shift_amount):


cipher_text = ""
for letter in plain_text:
position = alphabet.index(letter)
new_position = position + shift_amount
cipher_text += alphabet[new_position]
print(f"The encoded text is {cipher_text}")

def decrypt(plain_text, shift_amount):


cipher_text = ""
for letter in plain_text:
position =alphabet.index(letter)
new_position = position - shift_amount
cipher_text += alphabet[new_position]
print(f"The decoded text is {cipher_text}")

if direction == "encode":
encrypt(plain_text=text,
shift_amount=shift)
else:
decrypt(plain_text=text,
shift_amount=shift)
OUTPUT:
INPUT
Direction “encode”
Text Message “Bad”
Shift Value “2”
The Encoded value is DCF

Direction “decode”
Text Message “dcf”
Shift Value “2”
The Encoded value is BAD

FINAL CODE OF CYPHER PROGRAM EXERCISE

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 = alphabet.index(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}")

import art
print(art.logo)

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)

Restart = input("Type 'Yes' if u want to go


again. Otherwise No:\n")

if Restart == "No":
should_continue =False
print("Thanks for using the program")
OUTPUT:

INPUT
Direction “encode”
Text Message “Bad”
Shift Value “2”
The Encoded value is DCF
Type ‘Yes’ if you want to go again otherwise ‘No’

‘Yes’

Direction “decode”
Text Message “dcf”
Shift Value “2”
The Encoded value is BAD

Same Code is below with enhancement of Numbers and Symbols

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:
#TODO-3: What happens if the user enters
a number/symbol/space?
#Can you fix the code to keep the
number/symbol/space when the text is
encoded/decoded?
#e.g. start_text = "meet me at 3"
#end_text = "•••• •• •• 3"
position = alphabet.index(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}")

#TODO-1: Import and print the logo from


art.py when the program starts.
import art
print(art.logo)

#TODO-4: Can you figure out a way to ask the


user if they want to restart the cipher
program?
#e.g. Type 'yes' if you want to go again.
Otherwise type 'no'.
#If they type 'yes' then ask them for the
direction/text/shift again and call the
caesar() function again?
#Hint: Try creating a while loop that
continues to execute the program if the user
types 'yes'.
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)

Restart = input("Type 'Yes' if u want to go


again. Otherwise No:\n")

if Restart == "No":
should_continue =False
print("Thanks for using the program")

DICTIONARY (STUDENTS GRADES AND SCORES) EXERCISE


student_scores = {
"Harry": 81,
"Ron": 78,
"Hermione": 99,
"Draco": 74,
"Neville": 62,
}
# 🚨 Don't change the code above 👆

#TODO-1: Create an empty dictionary called


student_grades.

student_grades = {}

#TODO-2: Write your code below to add the


grades to student_grades.👇

for student in student_scores:


score = student_scores[student]
if score > 90:
student_grades[student] = "Outstanding"
elif score > 80 and score < 91:
student_grades[student] = "Exceeds
Expectations"
elif score > 70 and score < 81:
student_grades[student] = " Acceptable"
else:
student_grades[student] = "Fail"
# 🚨 Don't change the code below 👇
print(student_grades)

OUTPUT

{“Harry”: “Exceeds Expectations”, “Ron”: “Acceptable”, “Hermione”:


“Outstanding”, “Draco”: “Acceptable”, “Neville”: “Fail”}

AUCTION CODING EXERCISE

from replit import clear


#HINT: You can call clear() to clear the
output in the console.

import art
print(art.logo)

print("Welcome to the secret Auction


program")
close_bid = False

def highest_bidder(bidding_record):
high_bid = 0
winner = ""

for bidder in bidding_record:


bid_price = bidding_record[bidder]
if bid_price > high_bid:
high_bid = bid_price
winner = bidder
print(f"The winner is {winner} with the
highest bid of {high_bid}")

while not close_bid:

bidder_info = {}
#Take Input from Attendes
Attendes_info = input("What is your name?:
")
Bid_Amount = int(input("What's your bid?:
"))

bidder_info[Attendes_info] = Bid_Amount
#print(Bidder_Info)

#Ask for the other Attendes info


Attendes_others = input("Are there any
other bidders? type 'yes' or 'no' ")
if Attendes_others == "no":
close_bid = True
highest_bidder(bidder_info)
else:
clear()

LEAP YEAR CODE – RETURN VALUE EXERCISE

def is_leap(year):
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
return True
else:
return False
else:
return True
else:
return False

def days_in_month(year, month):


month_days = [31, 28, 31, 30, 31, 30, 31,
31, 30, 31, 30, 31]

if is_leap(year) and month == 2:


return 29
return month_days[month - 1]

#🚨 Do NOT change any of the code below


year = int(input("Enter a year: "))
month = int(input("Enter a month: "))
days = days_in_month(year, month)
print(days)
OUTPUT = YEAR – 2022 and MONTH – 2 = 28 Days
CALCULATOR PROJECT (TRY THIS PROJECT )

#Buiding Calculator Project

def Addition(n1,n2):
return n1 + n2

def Subtraction(n1,n2):
return n1 - n2

def Multiply(n1,n2):
return n1 * n2

def divide(n1,n2):
return n1 / n2
operation = { "+": Addition, "-":Subtraction,
"*":Multiply, "/":divide }

def calculator():
num1 = float(input("What is the first
number: "))

calculation_continue = True
while calculation_continue:
for symbol in operation:
print(symbol)

operation_symbol = input("Pick the symbol


from list: ")

num2 = float(input("What is the second


number: "))

calculation_function =
operation[operation_symbol]
first_answer = calculation_function(num1,
num2)

print(f"{num1} {operation_symbol} {num2}


= {first_answer}")

next_level = input("type 'yes' if you


want to continue with last answer, or type
'no' to exit, or type 'start' with from
Start: ")

if next_level == "no":
calculation_continue = False
calculator()

elif next_level == "yes":


num1 = first_answer

calculator()
PROJECT BLACKJACK – THIS IS MY CODE

############### Blackjack Project


#####################
from replit import clear

play_game = input("Do you want to play a game


of blackjack, type 'yes' or 'no': ")

def Blackjack():
Game_start = True
while Game_start:
if play_game == "yes":
import random
import art
print(art.logo)

cards = [11, 2, 3, 4, 5, 6, 7, 8, 9,
10, 10, 10, 10]

your_c1 = random.choice(cards)
your_c2 = random.choice(cards)
computer_c1 = random.choice(cards)

your_score = (your_c1 + your_c2)

print(f"Your cards:{[your_c1,your_c2]},
current score:{your_score}")
print(f"Computer's first card:
{computer_c1}")

next_step = input("Type 'y' to get


another card, type 'n' to pass: ")

if next_step == "y":
your_c3 = random.choice(cards)
computer_c2 = random.choice(cards)

your_total_score = (your_score +
your_c3)
computer_total_score = (computer_c1 +
computer_c2)

print(f"Your cards:
{[your_c1,your_c2,your_c3]}, current score:
{your_total_score}")

print(f"Computer's first card:


{computer_c1}")

print(f"your final hand:


{[your_c1,your_c2,your_c3]}, final score:
{your_total_score}")
print(f"computer final hand:
{[computer_c1,computer_c2]}, final score:
{computer_total_score}")

if your_total_score > 21:


print("you went over, you lose")

elif computer_total_score > 21:


print("computer went over, computer
lose")

else:
if your_total_score >
computer_total_score:
print("Congratulations you won.
")
elif your_total_score <
computer_total_score:
print("You lose, Computer won. ")

elif next_step == "n":


computer_c2 = random.choice(cards)

computer_total_score = (computer_c1 +
computer_c2)
print(f"your final hand:
{[your_c1,your_c2]}, final score:
{your_score}")

print(f"computer final hand:


{[computer_c1,computer_c2]}, final score:
{computer_total_score}")

if your_score > 21:


print("you went over, you lose")

elif computer_total_score > 21:


print("computer went over, computer
lose")

else:
if your_score >
computer_total_score:
print("Congratulations you won")
elif your_score <
computer_total_score:
print("You lose, computer won. ")

elif play_game== "no":


Game_start = False

print("Thanks for not playing now. ")


while play_game == "yes":
clear()
Blackjack()

OUTPUT – IF user provide “y” as input

OUTPUT – IF user provide “n” as input


#Number Guessing Game Objectives:

# Include an ASCII art logo.


# Allow the player to submit a guess for a
number between 1 and 100.
# Check user's guess against actual answer.
Print "Too high." or "Too low." depending on
the user's answer.
# If they got the answer correct, show the
actual answer to the player.
# Track the number of turns remaining.
# If they run out of turns, provide feedback
to the player.
# Include two different difficulty levels
(e.g., 10 guesses in easy mode, only 5
guesses in hard mode).

import random
#from art import logo
#print(logo)
print("Welcome to the Number guessing game!
")

print("I'm thinking of the number between 1 &


100. ")
Level= input("choose difficulty, type 'hard'
or 'easy': ")

number =
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18
,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33
,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48
,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63
,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78
,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93
,94,95,96,97,98,99,100]

final_num = random.choice(number)
print(final_num)

if Level == "hard":
guessing = False
while not guessing:
attempt = 5
for rem_attempt in range(attempt):
final_attempt = attempt - rem_attempt

print(f"You have {final_attempt}


attempts remaining to close the game. ")

Guess= int(input("Make a Guess: "))


if final_num == Guess:
print("You are right,
congratulations.")
guessing = True
break

else:
final_num != Guess
if final_num > Guess:
print("Too Low")
print("Guess again.")

else:
final_num < Guess
print("Too High")
print("Guess againnnn.")

else:
Level == "easy"
print("You have 10 attempts remaining to
guess the number.")
Guess= input("Make a Guess: ")
print(Guess)

You might also like