This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creates a function potion which asks you your starting health, the difficulty rating (which determines which range the | |
# health potion will heal you by. Finally you're asked if you would like to pick up the potion. | |
# Import the random package to generate random numbers | |
import random | |
# Define function potion | |
def potion(player_health, difficulty, pickup): | |
# Create health potion and convert to integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ask user for name | |
# Strip removes white space leading or trailing the answer | |
name = input("Hello, what is your name? ").strip() | |
# Ask user for age | |
age = input("How old are you in years? ").strip() | |
# Ask user for city | |
city = input("What city do you live in? ").strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get user email address | |
email = input("What is your email address?: ").strip() | |
# Slice out the user name | |
user_name = email[:email.index("@")] | |
# Slice the domain name | |
domain_name = email[email.index("@")+1:] | |
# Format message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a list of known users | |
known_users = ["Alice","Bob","Claire","Dan","Emma","Fred","Georgie","Harry"] | |
# How many users are there? | |
print(len(known_users)) | |
while True: | |
print("Hi! My name is Travis.") | |
# Create input varaible name and strip to remove blank spaces and capitalise first letter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a dictionary: students | |
students = { | |
"Alice": ["ID0001", 26, "A"] | |
, "Bob": ["ID0002", 27, "B"] | |
, "Claire": ["ID0003", 17, "C"] | |
, "Dan": ["ID0004", 21, "D"] | |
, "Emma": ["ID0005", 22, "E"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List films that we have at the cinema [age requirement, number of tickets available] | |
films = { | |
"Finding Dory": {"Age": 3, "Tickets Available": 5}, | |
"Bourne": {"Age": 15, "Tickets Available": 10}, | |
"Tarzan": {"Age": 12, "Tickets Available": 7}, | |
"Ghost Busters": {"Age": 12, "Tickets Available": 2}, | |
"High School Musical 3": {"Age": 5, "Tickets Available": 25}, | |
"The Brother's Grimm": {"Age": 12, "Tickets Available": 3}, | |
"Harry Potter": {"Age": 11, "Tickets Available": 1} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import choice from random package | |
from random import choice | |
# List of questions | |
questions = [ | |
"Why is the sky blue?: ", | |
"Why is there a face on the moon?: ", | |
"Where are all the dinosaurs?: " | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set x eq to 1 | |
x= 1 | |
# prints if x is less than 11 | |
while x < 11: | |
print(x) | |
x = x+1 | |
# prints if x is even but less than 100 | |
while x < 100: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# print numbers 1 to 50 | |
for number in range(1,50): | |
print(number) | |
# print letters a,b,c,d | |
for letter in 'abcd': | |
print(letter) | |
# Count number of vowels and consonants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create even numbers | |
even_numbers = [x for x in range(1,101) if x % 2 == 0] | |
print(even_numbers) | |
# Create odd numbers | |
odd_numbers = [x for x in range(1,101) if x % 2 == 1] | |
print(odd_numbers) | |
# Examples of list comprehensions | |
words = ["the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"] |
OlderNewer