Skip to content

Instantly share code, notes, and snippets.

View TomColBee's full-sized avatar

Thomas Beeson TomColBee

View GitHub Profile
@TomColBee
TomColBee / HelloYou.py
Created June 6, 2018 18:37
Python Bible: Hello You - Strings, Input and Format
# 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()
@TomColBee
TomColBee / HealthPotion.py
Last active June 6, 2018 18:40
Python Bible: User Defined Function, Conditional Statements, While Loops, Error Handling
# 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
@TomColBee
TomColBee / TravisSystem.py
Created June 10, 2018 19:24
Python Bible: Travis Project - Lists (Create, Append, Remove), Conditional Statements, Loops
# 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
@TomColBee
TomColBee / Dict_Practice.py
Created June 12, 2018 18:58
Python Bible: Dictionary Practice
# 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"]
}
@TomColBee
TomColBee / BabySimulator.py
Created June 17, 2018 16:26
Python Bible: Baby Simulator Project - While Loop - Random Choice
# 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?: "
]
@TomColBee
TomColBee / SimpleWhileLoops.py
Created June 17, 2018 16:27
Python Bible - Simple While Loop examples
# 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:
@TomColBee
TomColBee / ForLoopExamples.py
Created June 17, 2018 16:40
Python Bible: For Loops Examples
# 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
@TomColBee
TomColBee / ListComprehensionExamples.py
Created June 17, 2018 16:47
Python Bible: List comprehension examples
# 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"]
@TomColBee
TomColBee / GuessTheNumber.py
Created June 17, 2018 21:34
Guess The Number Project
# 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.")
@TomColBee
TomColBee / QuizTemplate.py
Created June 19, 2018 17:23
Project: Multiple Choice Quiz Template
# 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...")