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
# 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
# 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
# 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"] |
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
# Program where the user has to guess the number in the given number of lives. | |
# User inputs the difficulty which determines the range the number is generated from. | |
# User also inputs the number of guesses they feel they need. | |
# import random package | |
import random | |
# Print welcome to the game | |
print("Hello, welcome to the number guessing game.") |
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
# Multiple choice quiz sample code | |
# Complete the lists detailed below | |
# question_titles, questions_asked, poss_answers, answers_ page ref. | |
# Import random package and sys | |
import random | |
# Print welcome | |
print("Hello, welcome to the [Quiz Name Here]." | |
"\nBefore we start, let me ask a few questions...") |
OlderNewer