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 board | |
board = [" " for i in range(9)] | |
# print instructions | |
print("Hello, welcome to Tic Tac Toe!") | |
print() | |
print("To play, just input the number of the space you wish to have...") | |
row1 = "| 1 | 2 | 3 |" |
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
# Hangman game | |
# import packages | |
import random | |
import os | |
# define function to replace "?" with letters guessed | |
def progress(word, question_marks, letter): | |
progress = "" | |
for i in range(0,len(word)): |
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
# Have the function FirstFactorial(num) take the num parameter being passed and return the factorial of it. | |
# E.g. if num = 4, return (4 * 3 * 2 * 1) = 10. | |
# For the test cases, the range will be between 1 and 18 and the input will always be an integer. | |
def FirstFactorial(num): | |
# Set var sum to be 1 | |
sum = 1 | |
# For x in the range 2 to num+1, let sum be equal to sum multiplied by x ------- range(start, stop, step) |
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
# Have the function FirstReverse(str) take the str parameter being passed and return the string in reversed order. | |
# For example: "Hello World and Coders" should return the string "sredoC dna dlroW olleH". | |
def FirstReverse(str): | |
str = str[::-1] | |
return str | |
print FirstReverse(raw_input()) |
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
# Have the function LetterChanges(str) take the str parameter being passed | |
# and modify it using the following algorithm. | |
# Replace every letter in the string with the letter following it in the alphabet | |
# (ie. c becomes d, z becomes a). | |
# Then capitalize every vowel in this new string (a, e, i, o, u) and | |
# finally return this modified string. | |
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
# Hedgehog Dodge Game | |
# Game where the user moves the hedgehog left or right to dodge falling blocks | |
# Blocks fall quicker as the game progresses | |
import pygame, sys, os, time, random | |
from pygame.locals import * | |
pygame.init() # initialise pygame | |
FPS = 30 # set frames per second | |
fpsClock = pygame.time.Clock() # set fpsClock |
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
def diamond(n): | |
orig_n = int(n) | |
orig_n_2 = int(n) | |
# first line of star | |
spaces = int(n-1) | |
print(" " * spaces + "*") | |
# middle section |
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
def diamond_letters(n): | |
# convert string to upper case | |
n = n.upper() | |
# create letter string | |
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
# find given letter n in the letters string and return index+1 | |
n = letters.find(n) + 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
# 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
# Machine learning example using iris dataset | |
# Classification problem. | |
# Uses a variety of different algorithms to predict class based on sepal/petal lengths and widths | |
# Python version 3.6 | |
# Source: https://machinelearningmastery.com/machine-learning-in-python-step-by-step/ | |
# Step 1: Check Python versions | |
# Step 2: Load libraries | |
# Step 3: Load dataset |