0% found this document useful (0 votes)
38 views10 pages

Day 3 Solution Files

The document contains multiple Python scripts that implement various programs, including a rollercoaster ticketing system, a pizza ordering system, and a text-based treasure island adventure game. Each script uses conditional statements to determine outcomes based on user input, such as height and age for the rollercoaster, pizza size and toppings for the pizza order, and choices made during the treasure hunt. The scripts demonstrate the use of if-else statements, logical operators, and user interaction in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views10 pages

Day 3 Solution Files

The document contains multiple Python scripts that implement various programs, including a rollercoaster ticketing system, a pizza ordering system, and a text-based treasure island adventure game. Each script uses conditional statements to determine outcomes based on user input, such as height and age for the rollercoaster, pizza size and toppings for the pizza order, and choices made during the treasure hunt. The scripts demonstrate the use of if-else statements, logical operators, and user interaction in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Folder: If Else - File: solution.

py
print("Welcome to the rollercoaster!")

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

if height >= 120:

print("You can ride the rollercoaster")

else:

print("Sorry you have to grow taller before you can ride.")


Folder: Logical Operators - File: solution.py
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.")

elif age >= 45 and age <= 55:

# Or

# 45 <= age <= 55

print("Everything is going to be ok. Have a free ride on us!")

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


Folder: Modulo - File: solution.py
number_to_check = int(input("What is the number you want to check? "))

if number_to_check % 2 == 0:

print("Even")

else:

print("Odd")
Folder: Multiple Ifs - File: solution.py
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.")


Folder: Nesting and Elif - File: solution.py
print("Welcome to the rollercoaster!")

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

if height >= 120:

print("You can ride the rollercoaster")

age = int(input("What is your age? "))

if age <= 12:

print("Please pay $5.")

elif age <= 18:

print("Please pay $7.")

else:

print("Please pay $12.")

else:

print("Sorry you have to grow taller before you can ride.")


Folder: Python Pizza - File: solution.py
print("Welcome to Python Pizza Deliveries!")

size = input("What size pizza do you want? S, M or L: ")

pepperoni = input("Do you want pepperoni on your pizza? Y or N: ")

extra_cheese = input("Do you want extra cheese? Y or N: ")

# todo: work out how much they need to pay based on their size choice.

bill = 0

if size == "S":

bill += 15

elif size == "M":

bill += 20

elif size == "L":

bill += 25

else:

print("You have chosen an invalid size.")

# todo: work out how much to add to their bill based on their pepperoni choice.

if pepperoni == "Y":

if size == "S":

bill += 2

else:

bill += 3

# todo: work out their final amount based on whether if they want extra cheese.
if extra_cheese == "Y":

bill += 1

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


Folder: Treasure Island Project - File: solution.py
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.")

choice1 = input('You\'re at a crossroad, where do you want to go? '

'Type "left" or "right".\n').lower()


if choice1 == "left":

choice2 = input('You\'ve come to a lake. '

'There is an island in the middle of the lake. '

'Type "wait" to wait for a boat. '

'Type "swim" to swim across.\n').lower()

if choice2 == "wait":

choice3 = input("You arrive at the island unharmed. "

"There is house with 3 doors. One red, "

"one yellow and one blue. "

"Which colour do you choose?\n").lower()

if choice3 == "red":

print("It's a room full of fire. Game Over")

elif choice3 == "yellow":

print("You found the treasure. You Win!")

elif choice3 == "blue":

print("You enter a room of beasts. Game Over.")

else:

print("You chose a door that doesn't exist. Game Over.")

else:

print("You got attacked by an angry trout. Game Over.")

else:

print("You fell in to a hole. Game Over.")

You might also like