Python Code Files Assignment
Python Code Files Assignment
####################################
#Write your code below this line 👇
print(two_digit_number)
OUTPUT
INPUT = 55
OUTPUT = 5 + 5 =10
#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
#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)
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)
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."
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
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
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)
import random
Human_Value = Input_value
Pc_value = random.randint(0,2)
print(game_images[Human_Value])
print(game_images[Pc_value])
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 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
# 🚨 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)
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
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@
#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
#Testing code
print(f'Pssst, the solution is
{chosen_word}.')
#Create blanks
display = []
for _ in range(word_length):
display += "_"
print(f"{' '.join(display)}")
#Step 5
import random
import hangman_words
import hangman_art
end_of_game = False
lives = 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()
if guess in display:
print(f"You have already guess {guess}.
")
print(f"{' '.join(display)}")
#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
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
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)
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
shift = shift % 26
caesar(start_text=text, shift_amount=shift,
cipher_direction=direction)
if Restart == "No":
should_continue =False
print("Thanks for using the program")
student_grades = {}
OUTPUT
import art
print(art.logo)
def highest_bidder(bidding_record):
high_bid = 0
winner = ""
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)
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 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)
calculation_function =
operation[operation_symbol]
first_answer = calculation_function(num1,
num2)
if next_level == "no":
calculation_continue = False
calculator()
calculator()
PROJECT BLACKJACK – THIS IS MY CODE
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)
print(f"Your cards:{[your_c1,your_c2]},
current score:{your_score}")
print(f"Computer's first card:
{computer_c1}")
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}")
else:
if your_total_score >
computer_total_score:
print("Congratulations you won.
")
elif your_total_score <
computer_total_score:
print("You lose, Computer won. ")
computer_total_score = (computer_c1 +
computer_c2)
print(f"your final hand:
{[your_c1,your_c2]}, final score:
{your_score}")
else:
if your_score >
computer_total_score:
print("Congratulations you won")
elif your_score <
computer_total_score:
print("You lose, computer won. ")
import random
#from art import logo
#print(logo)
print("Welcome to the Number guessing game!
")
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
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)