Add lots of old weird school stuff
37
gcse computer science/year 10/API Hangman.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
guessed = []
|
||||||
|
correct = []
|
||||||
|
|
||||||
|
# Get a word from the API
|
||||||
|
word = urllib.request.urlopen('http://random-word-api.herokuapp.com/word?number=1').read().decode()
|
||||||
|
word = str(word[2:len(word)-2])
|
||||||
|
print(word)
|
||||||
|
|
||||||
|
lives = 6
|
||||||
|
letters = []
|
||||||
|
for i in word:
|
||||||
|
letters.append(i)
|
||||||
|
|
||||||
|
while lives != 0:
|
||||||
|
# Take in a guess
|
||||||
|
letter = input('Please enter a letter: ').lower()
|
||||||
|
# Ensure that the letter is valid, and has not already been guessed
|
||||||
|
if len(letter) > 1 or letter.isnumeric():
|
||||||
|
print('That is not a letter!')
|
||||||
|
continue
|
||||||
|
if letter in guessed:
|
||||||
|
print('You have already guessed \'{0}\'!'.format(letter))
|
||||||
|
continue
|
||||||
|
# Ensure that the letter is in the word - if not, subtract a life
|
||||||
|
if letter in word:
|
||||||
|
correct.append(letter) # Add the letter to the correct list
|
||||||
|
# If the unordered list of correct letters is the same as the unordered list of letters in the word, the player wins
|
||||||
|
if set(correct) == set(letters):
|
||||||
|
print('You won, with {0} lives to spare! The word was {1}'.format(str(lives), word))
|
||||||
|
lives = 0
|
||||||
|
else:
|
||||||
|
lives -= 1
|
||||||
|
print('Uh oh! \'{0}\' is wrong! You have {1} lives left.'.format(letter, str(lives)))
|
||||||
|
|
||||||
|
guessed.append(letter)
|
208
gcse computer science/year 10/Calculator [GUI].py
Normal file
|
@ -0,0 +1,208 @@
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Name: calculator v1.2 - decimal point added
|
||||||
|
# Purpose: calculator using TKinter
|
||||||
|
#
|
||||||
|
# Author: L Jacob
|
||||||
|
#
|
||||||
|
# Created: 23/07/2015
|
||||||
|
# Copyright: (c) L Jacob 2015
|
||||||
|
# Licence: <your licence>
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
from tkinter import *
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
##Functions for mathematic operations##
|
||||||
|
def add(a, b):
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
def subtract(a, b):
|
||||||
|
return a - b
|
||||||
|
|
||||||
|
def divide(a, b):
|
||||||
|
return a / b
|
||||||
|
|
||||||
|
def multiply(a,b):
|
||||||
|
return a * b
|
||||||
|
|
||||||
|
def updateDisplay(update):
|
||||||
|
##Function to display results##
|
||||||
|
outputLbl.configure(text = str(update))
|
||||||
|
|
||||||
|
def handlerEquals(event):
|
||||||
|
##Event handler for equals button##
|
||||||
|
##Function requires operand to be specified so that correct operation is performed##
|
||||||
|
global first_num ## use the variable of this name that has been created outside of this function, i.e. our 'global' variable
|
||||||
|
global second_num
|
||||||
|
global operand
|
||||||
|
|
||||||
|
##convert user inputs to numbers ready to do the maths##
|
||||||
|
first_num = Decimal(first_num)
|
||||||
|
second_num = Decimal(second_num)
|
||||||
|
|
||||||
|
if operand != None:
|
||||||
|
if operand == '+':
|
||||||
|
result = add(first_num,second_num)
|
||||||
|
elif operand == '-':
|
||||||
|
result = subtract(first_num,second_num)
|
||||||
|
elif operand == '/':
|
||||||
|
if second_num == 0:
|
||||||
|
result = 'You can not divide by zero!'
|
||||||
|
first_num = None
|
||||||
|
second_num = None
|
||||||
|
operand = None
|
||||||
|
else:
|
||||||
|
result = divide(first_num,second_num)
|
||||||
|
elif operand == '*':
|
||||||
|
result = multiply(first_num,second_num)
|
||||||
|
updateDisplay(result)
|
||||||
|
|
||||||
|
def handlerOperand(event):
|
||||||
|
##Event Handler for operation buttons##
|
||||||
|
##Function to store users choice of add, subtract, divide, multiply##
|
||||||
|
global operand
|
||||||
|
caller = event.widget['text'] #get the text value of the button that is passed in to the handler
|
||||||
|
if operand == None:
|
||||||
|
operand = caller
|
||||||
|
updateDisplay(0)
|
||||||
|
else:
|
||||||
|
pass ##prevent the operand from being changed accidentally
|
||||||
|
|
||||||
|
def handlerNumbers(event):
|
||||||
|
##Event Handler for number buttons##
|
||||||
|
##Function puts user input in first_num if operand is empty, otherwise input goes second_num##
|
||||||
|
global first_num
|
||||||
|
global second_num
|
||||||
|
global operand
|
||||||
|
|
||||||
|
caller = event.widget['text'] #get the text value of the button that is passed in to the handler
|
||||||
|
|
||||||
|
if operand == None:
|
||||||
|
if first_num == None: #check to see if num is set to None as we cannot append to none - must overwrite
|
||||||
|
first_num = caller
|
||||||
|
updateDisplay(first_num)
|
||||||
|
else:
|
||||||
|
first_num = first_num + caller
|
||||||
|
updateDisplay(first_num)
|
||||||
|
else:
|
||||||
|
if second_num == None:
|
||||||
|
second_num = caller
|
||||||
|
updateDisplay(second_num)
|
||||||
|
else:
|
||||||
|
second_num = second_num + caller
|
||||||
|
updateDisplay(second_num)
|
||||||
|
|
||||||
|
def handlerClear(event):
|
||||||
|
##Event handler for C button##
|
||||||
|
##Resets variables and updates the display##
|
||||||
|
global first_num
|
||||||
|
global second_num
|
||||||
|
global operand
|
||||||
|
|
||||||
|
first_num = None
|
||||||
|
second_num = None
|
||||||
|
operand = None
|
||||||
|
|
||||||
|
updateDisplay(0)
|
||||||
|
|
||||||
|
|
||||||
|
##MAIN BODY CODE STARTS##
|
||||||
|
|
||||||
|
##setup gobal variables that all functions can access##
|
||||||
|
first_num = None
|
||||||
|
second_num = None
|
||||||
|
operand = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
window = Tk()#create the window#
|
||||||
|
# Code to add widgets will go here...
|
||||||
|
|
||||||
|
##Setup frames##
|
||||||
|
topframe = Frame(window)
|
||||||
|
topframe.pack()
|
||||||
|
|
||||||
|
bottomframe = Frame(window)
|
||||||
|
bottomframe.pack(side = BOTTOM)
|
||||||
|
##setup label to display output in top frame##
|
||||||
|
outputLbl = Label(topframe, text = "0")
|
||||||
|
outputLbl.pack()
|
||||||
|
##setup number buttons in grid layout within bottom frame##
|
||||||
|
b1 = Button(bottomframe, text='1')
|
||||||
|
b1.bind("<1>", handlerNumbers)
|
||||||
|
b1.grid(row=0, column = 0)
|
||||||
|
|
||||||
|
b2 = Button(bottomframe, text='2') ## create Button called b2 that is inside the bottom frame and displays the label '2'##
|
||||||
|
b2.bind("<1>", handlerNumbers) ##on b2, bind the event 'when mouse button 1 is clicked (i.e. left mouse button), call the function named 'handlerNumbers'##
|
||||||
|
b2.grid(row=0, column = 1) ##place button b2 in a grid within its frame, in 0 down and 1 across##
|
||||||
|
|
||||||
|
b3 = Button(bottomframe, text='3')
|
||||||
|
b3.bind("<1>", handlerNumbers)
|
||||||
|
b3.grid(row=0, column = 2)
|
||||||
|
|
||||||
|
b4 = Button(bottomframe, text='4')
|
||||||
|
b4.bind("<1>", handlerNumbers)
|
||||||
|
b4.grid(row=1, column = 0)
|
||||||
|
|
||||||
|
b5 = Button(bottomframe, text='5')
|
||||||
|
b5.bind("<1>", handlerNumbers)
|
||||||
|
b5.grid(row=1, column = 1)
|
||||||
|
|
||||||
|
b6 = Button(bottomframe, text='6')
|
||||||
|
b6.bind("<1>", handlerNumbers)
|
||||||
|
b6.grid(row=1, column = 2)
|
||||||
|
|
||||||
|
b7 = Button(bottomframe, text='7')
|
||||||
|
b7.bind("<1>", handlerNumbers)
|
||||||
|
b7.grid(row=2, column = 0)
|
||||||
|
|
||||||
|
b8 = Button(bottomframe, text='8')
|
||||||
|
b8.bind("<1>", handlerNumbers)
|
||||||
|
b8.grid(row=2, column = 1)
|
||||||
|
|
||||||
|
b9 = Button(bottomframe, text='9')
|
||||||
|
b9.bind("<1>", handlerNumbers)
|
||||||
|
b9.grid(row=2, column = 2)
|
||||||
|
|
||||||
|
b0 = Button(bottomframe, text='0')
|
||||||
|
b0.bind("<1>", handlerNumbers)
|
||||||
|
b0.grid(row=3, column = 1)
|
||||||
|
|
||||||
|
bDot = Button(bottomframe, text='.')##decimal point button
|
||||||
|
bDot.bind("<1>", handlerNumbers)
|
||||||
|
bDot.grid(row=4, column = 0)
|
||||||
|
|
||||||
|
##setup operand buttons##
|
||||||
|
|
||||||
|
bPlus = Button(bottomframe, text='+')
|
||||||
|
bPlus.bind("<1>", handlerOperand)
|
||||||
|
bPlus.grid(row=4, column = 2)
|
||||||
|
|
||||||
|
bMinus = Button(bottomframe, text='-')
|
||||||
|
bMinus.bind("<1>", handlerOperand)
|
||||||
|
bMinus.grid(row=4, column = 3)
|
||||||
|
|
||||||
|
bDivide = Button(bottomframe, text='/')
|
||||||
|
bDivide.bind("<1>", handlerOperand)
|
||||||
|
bDivide.grid(row=5, column = 2)
|
||||||
|
|
||||||
|
bMultiply = Button(bottomframe, text='*')
|
||||||
|
bMultiply.bind("<1>", handlerOperand)
|
||||||
|
bMultiply.grid(row=5, column = 3)
|
||||||
|
|
||||||
|
bEquals = Button(bottomframe, text='=')
|
||||||
|
bEquals.bind("<1>", handlerEquals)
|
||||||
|
bEquals.grid(row=6, column=0)
|
||||||
|
|
||||||
|
##setup Clear button##
|
||||||
|
|
||||||
|
bClear = Button(bottomframe, text='C')
|
||||||
|
bClear.bind("<1>", handlerClear)
|
||||||
|
bClear.grid(row=6, column=2)
|
||||||
|
|
||||||
|
## Code to add widgets ends. Mainloop keeps program running whilst waiting for user input##
|
||||||
|
window.mainloop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
71
gcse computer science/year 10/Calculator.py
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
operators=["+","-", "*", "/"] #list of operators
|
||||||
|
operatorNames=["add","subtract","multiply","divide"]
|
||||||
|
|
||||||
|
def addNums(num1, num2):
|
||||||
|
"""Function to return to sum of the parameters"""
|
||||||
|
answer = num1+num2
|
||||||
|
return answer
|
||||||
|
|
||||||
|
def subNums(num1,num2):
|
||||||
|
answer = num1-num2
|
||||||
|
return answer
|
||||||
|
|
||||||
|
def multiplyNums(num1,num2):
|
||||||
|
answer = num1*num2
|
||||||
|
return answer
|
||||||
|
|
||||||
|
def divideNums(num1,num2):
|
||||||
|
answer = num1/num2
|
||||||
|
return answer
|
||||||
|
|
||||||
|
def checkChoice():
|
||||||
|
global operators
|
||||||
|
choice = (input("Enter the operator"))
|
||||||
|
if choice in operators:
|
||||||
|
return choice
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("Error!")
|
||||||
|
return ""
|
||||||
|
#end of choice check
|
||||||
|
def menu():
|
||||||
|
"""Subroutine to run the menu"""
|
||||||
|
global operators # global variable to access the list of operators
|
||||||
|
global operatorNames # global variable to access the list of operator names
|
||||||
|
choice = "" #declare an empty string variable to hold the user's choice of operator
|
||||||
|
answer = 0 #declare an integer variable to hold the result
|
||||||
|
number1 = int(input("Enter Number 1"))
|
||||||
|
number2 = int(input("Enter Number 2"))
|
||||||
|
#-----------------print the accepted operators--------------------
|
||||||
|
print ("Select the operator:")
|
||||||
|
for i in range(0,len(operators)):
|
||||||
|
print(operators[i]," ", operatorNames[i])
|
||||||
|
#-----------------call the checkChoice function--------------------
|
||||||
|
while choice=="":
|
||||||
|
choice = checkChoice()
|
||||||
|
#-----------------call the correct operator function--------------------
|
||||||
|
if choice == "+":
|
||||||
|
answer = addNums(number1,number2)
|
||||||
|
elif choice =="-":
|
||||||
|
answer = subNums(number1,number2)
|
||||||
|
elif choice == "*":
|
||||||
|
answer = multiplyNums(number1,number2)
|
||||||
|
elif choice == "/":
|
||||||
|
if number2 == 0:
|
||||||
|
print('You can not divide by zero!')
|
||||||
|
menu()
|
||||||
|
else:
|
||||||
|
answer = divideNums(number1,number2)
|
||||||
|
else:
|
||||||
|
print("sorry something went wrong!")
|
||||||
|
#-----------------output--------------------
|
||||||
|
print(number1, choice, number2, "=", answer)
|
||||||
|
return
|
||||||
|
|
||||||
|
menu()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
89
gcse computer science/year 10/Cat or Dog (Graphics).py
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
from tkinter import *
|
||||||
|
|
||||||
|
def addCat(event):
|
||||||
|
global pets
|
||||||
|
pets['cats'] = pets['cats'] + 1
|
||||||
|
updateDisplay()
|
||||||
|
|
||||||
|
def addDog(event):
|
||||||
|
global pets
|
||||||
|
pets['dogs'] = pets['dogs'] + 1
|
||||||
|
updateDisplay()
|
||||||
|
|
||||||
|
def addHamster(event):
|
||||||
|
global pets
|
||||||
|
pets['hamsters'] = pets['hamsters'] + 1
|
||||||
|
updateDisplay()
|
||||||
|
|
||||||
|
def addOther(event):
|
||||||
|
global pets
|
||||||
|
content = txtBox.get()
|
||||||
|
txtBox.delete(0, 'end')
|
||||||
|
|
||||||
|
if content.lower() not in pets:
|
||||||
|
pets[content.lower()] = 1
|
||||||
|
else:
|
||||||
|
pets[content.lower()] = pets[content.lower()] + 1
|
||||||
|
updateDisplay()
|
||||||
|
|
||||||
|
def reset(event):
|
||||||
|
global pets
|
||||||
|
|
||||||
|
for i in pets:
|
||||||
|
pets[i] = 0
|
||||||
|
|
||||||
|
updateDisplay()
|
||||||
|
|
||||||
|
def updateDisplay():
|
||||||
|
global pets
|
||||||
|
|
||||||
|
outputStr = 'There are '
|
||||||
|
|
||||||
|
for i in pets:
|
||||||
|
outputStr += '{0} {1}, '.format(pets[i], i)
|
||||||
|
|
||||||
|
##Function to display results##
|
||||||
|
outputLbl.configure(text = outputStr)
|
||||||
|
|
||||||
|
pets = { 'cats': 0, 'dogs': 0, 'hamsters': 0 }
|
||||||
|
|
||||||
|
window = Tk()#create the window#
|
||||||
|
window.title("Jacob's")
|
||||||
|
# Code to add widgets will go here...
|
||||||
|
##Setup frames##
|
||||||
|
topframe = Frame(window)
|
||||||
|
topframe.pack()
|
||||||
|
|
||||||
|
bottomframe = Frame(window)
|
||||||
|
bottomframe.pack(side = BOTTOM)
|
||||||
|
##setup label to display output in top frame##
|
||||||
|
welcome = Label(topframe, fg="red", font=("Helvetica", 16), text = "Welcome to Cat or Dog Selector")
|
||||||
|
welcome.pack()
|
||||||
|
|
||||||
|
outputLbl = Label(topframe, text = "0")
|
||||||
|
outputLbl.pack()
|
||||||
|
#setup buttons in grid layout within bottom frame##
|
||||||
|
catBtn = Button(bottomframe, text='Cat')
|
||||||
|
catBtn.bind("<1>", addCat)
|
||||||
|
catBtn.grid(row=0, column=1)
|
||||||
|
|
||||||
|
dogBtn = Button(bottomframe, text='Dog')
|
||||||
|
dogBtn.bind("<1>", addDog)
|
||||||
|
dogBtn.grid(row=0, column=2)
|
||||||
|
|
||||||
|
hamBtn = Button(bottomframe, text='Hamster')
|
||||||
|
hamBtn.bind('<1>', addHamster)
|
||||||
|
hamBtn.grid(row=0, column=3)
|
||||||
|
|
||||||
|
txtBox = Entry(bottomframe)
|
||||||
|
txtBox.grid(row=2, column=2)
|
||||||
|
submit = Button(bottomframe, text='Submit')
|
||||||
|
submit.bind('<1>', addOther)
|
||||||
|
submit.grid(row=2, column=3)
|
||||||
|
|
||||||
|
r = Button(bottomframe, text='Reset')
|
||||||
|
r.bind('<1>', reset)
|
||||||
|
r.grid(row=1, column=2)
|
||||||
|
|
||||||
|
# Code to add widgets ends. Mainloop keeps program running whilst waiting for user input##
|
||||||
|
window.mainloop()
|
26
gcse computer science/year 10/Cat or Dog (No Graphics).py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
def catOrDog():
|
||||||
|
global cat, dog
|
||||||
|
got = input('Enter what type of pet you have')
|
||||||
|
got = got.lower()
|
||||||
|
|
||||||
|
if got == 'dog':
|
||||||
|
dog = dog + 1
|
||||||
|
elif got == 'cat':
|
||||||
|
cat = cat + 1
|
||||||
|
else:
|
||||||
|
print('Only cats and dogs count.')
|
||||||
|
|
||||||
|
def printTotals():
|
||||||
|
global cat, dog
|
||||||
|
print('Total cats: {0}'.format(cat))
|
||||||
|
print('Total dogs: {0}'.format(dog))
|
||||||
|
|
||||||
|
cat = 0
|
||||||
|
dog = 0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
catOrDog()
|
||||||
|
printTotals()
|
||||||
|
again = input('Again? y/n')
|
||||||
|
if again == 'n':
|
||||||
|
break
|
46
gcse computer science/year 10/Temperature Bar Chart.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Name: Temperature Bar Chart Project
|
||||||
|
# Purpose: A turtle program that draws a bar chart based on an array of
|
||||||
|
# inputted floats.
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import turtle
|
||||||
|
|
||||||
|
# sub-routine to draw a bar
|
||||||
|
def drawBar(t, h):
|
||||||
|
t.left(90)
|
||||||
|
t.forward(h)
|
||||||
|
t.right(90)
|
||||||
|
t.forward(40)
|
||||||
|
t.right(90)
|
||||||
|
t.forward(h)
|
||||||
|
t.left(90)
|
||||||
|
|
||||||
|
# collect data
|
||||||
|
inp = input('Please input your list of floats. Separate each float by a comma.')
|
||||||
|
inp = inp.split(',')
|
||||||
|
|
||||||
|
data = []
|
||||||
|
for i in inp:
|
||||||
|
data.append(float(i))
|
||||||
|
|
||||||
|
maxheight = max(data)
|
||||||
|
numbars = len(data)
|
||||||
|
border = 10
|
||||||
|
|
||||||
|
# create a window
|
||||||
|
wn = turtle.Screen()
|
||||||
|
wn.setworldcoordinates(0-border, 0-border, 40*numbars+border, maxheight+border)
|
||||||
|
wn.bgcolor('lightgreen')
|
||||||
|
|
||||||
|
# create a turtle
|
||||||
|
t = turtle.Turtle()
|
||||||
|
t.color('blue')
|
||||||
|
t.fillcolor('red')
|
||||||
|
t.pensize(3)
|
||||||
|
|
||||||
|
# draw bars
|
||||||
|
for i in data:
|
||||||
|
drawBar(t, i)
|
||||||
|
|
||||||
|
wn.exitonclick()
|
76
gcse computer science/year 10/mark analyser/Mark Analyser.py
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
MAX = 45
|
||||||
|
classes = {}
|
||||||
|
|
||||||
|
def mean(x):
|
||||||
|
return sum(x) / len(x)
|
||||||
|
|
||||||
|
def median(x):
|
||||||
|
n = len(x)
|
||||||
|
i = n // 2
|
||||||
|
if n % 2:
|
||||||
|
return sorted(x)[i]
|
||||||
|
return sum(sorted(x)[i - 1:i + 1]) / 2
|
||||||
|
|
||||||
|
# Read the data file
|
||||||
|
data = open('marks.csv')
|
||||||
|
lines = data.readlines()
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
# Figure out the name of the class
|
||||||
|
lineNumber = lines.index(line) + 1
|
||||||
|
className = 'Class ' + str(lineNumber)
|
||||||
|
# Parse the csv to figure out the marks for each class
|
||||||
|
marks = line.split(',')
|
||||||
|
for i in marks:
|
||||||
|
index = marks.index(i)
|
||||||
|
marks[index] = int(i) # Ensure all of the marks are formatted as integers
|
||||||
|
# Ensure that the max amount of marks is not breached
|
||||||
|
for i in marks:
|
||||||
|
if i > MAX:
|
||||||
|
raise Exception('Line/Class {0} contains a mark higher than the max attainable ({1})'.format(str(lineNumber), str(MAX)))
|
||||||
|
# Initialise the class dictionary, and assign the marks value
|
||||||
|
classes[className] = {}
|
||||||
|
classes[className]['marks'] = marks
|
||||||
|
# Calculate the mean and median for each class
|
||||||
|
classes[className]['mean'] = mean(marks)
|
||||||
|
classes[className]['median'] = median(marks)
|
||||||
|
# Calculate how many students are above and below the median
|
||||||
|
above = 0
|
||||||
|
below = 0
|
||||||
|
for i in marks:
|
||||||
|
if i > classes[className]['median']:
|
||||||
|
above += 1
|
||||||
|
elif i < classes[className]['median']:
|
||||||
|
below += 1
|
||||||
|
classes[className]['aboveMedian'] = above
|
||||||
|
classes[className]['belowMedian'] = below
|
||||||
|
|
||||||
|
# Find the class with the highest mean
|
||||||
|
allMeans = []
|
||||||
|
|
||||||
|
for i in classes:
|
||||||
|
allMeans.append(classes[i]['mean']) # Put all of the means into a list
|
||||||
|
|
||||||
|
highestMean = max(allMeans) # Find the highest of those means
|
||||||
|
|
||||||
|
for i in classes:
|
||||||
|
for k, v in classes[i].items():
|
||||||
|
if k == 'mean' and v == highestMean: # Find the matching key and value
|
||||||
|
highestMean = i # Set the highestMean to the class name
|
||||||
|
|
||||||
|
# Find the median across all classes
|
||||||
|
allMarks = []
|
||||||
|
|
||||||
|
for i in classes:
|
||||||
|
allMarks += classes[i]['marks'] # Concatenate all marks lists
|
||||||
|
|
||||||
|
medianAcross = median(allMarks) # Find the median of that concatenated list
|
||||||
|
|
||||||
|
# Output
|
||||||
|
print('Results!\n-----------')
|
||||||
|
|
||||||
|
for i in classes:
|
||||||
|
c = classes[i]
|
||||||
|
print('{0}:\n\nMean: {1}\nMedian: {2}\nAbove Median: {3}\nBelow Median: {4}\n-----------'.format(i, str(c['mean']), str(c['median']), str(c['aboveMedian']), str(c['belowMedian'])))
|
||||||
|
|
||||||
|
print('\nClass with the highest mean mark: {0}\nMedian mark across all classes: {1}'.format(str(highestMean), str(medianAcross)))
|
2
gcse computer science/year 10/mark analyser/marks.csv
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
17,22,8,31,30,29,16,17,23,32
|
||||||
|
23,6,25,44,19,21,8,18,29,41
|
|
60
gcse computer science/year 10/oop dice/OOP Dice V2.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
class Dice:
|
||||||
|
# Initialise the class - make the default amount of sides 6
|
||||||
|
def __init__(self, sides=6):
|
||||||
|
self.sides = sides
|
||||||
|
|
||||||
|
# Roll the dice once - return an integer
|
||||||
|
def roll(self):
|
||||||
|
return randint(1, self.sides)
|
||||||
|
|
||||||
|
class Player:
|
||||||
|
# Initialise the class - create a dice and initialise the score parameter
|
||||||
|
def __init__(self, id, dice):
|
||||||
|
self.id = id
|
||||||
|
self.dice = dice
|
||||||
|
self.score = 0
|
||||||
|
self.rolls = []
|
||||||
|
|
||||||
|
# Roll the dice a specified amount of times - return an array of integers
|
||||||
|
def rollMany(self, times):
|
||||||
|
for i in range(times):
|
||||||
|
num = self.dice.roll()
|
||||||
|
self.rolls.append(num)
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.rolls = []
|
||||||
|
self.score = 0
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
def __init__(self, *player):
|
||||||
|
self.players = player
|
||||||
|
|
||||||
|
def determineWinner(self):
|
||||||
|
scores = {}
|
||||||
|
for i in self.players:
|
||||||
|
i.score = sum(i.rolls)
|
||||||
|
scores[i.id] = i.score
|
||||||
|
highestScore = max(scores.values())
|
||||||
|
for player, score in scores.items():
|
||||||
|
if score == highestScore:
|
||||||
|
if list(scores.values()).count(highestScore) > 1:
|
||||||
|
drew = []
|
||||||
|
for i in self.players:
|
||||||
|
if i.score == highestScore:
|
||||||
|
drew.append(str(i.id))
|
||||||
|
print("Players {0} have drawn first place with {1} score!".format(', '.join(drew), highestScore))
|
||||||
|
else:
|
||||||
|
playerInfo = self.players[player - 1]
|
||||||
|
print("Player {0} wins with {1} score!".format(player, playerInfo.score))
|
||||||
|
break
|
||||||
|
|
||||||
|
dice = Dice()
|
||||||
|
p1 = Player(1, dice)
|
||||||
|
p2 = Player(2, dice)
|
||||||
|
p1.rollMany(6)
|
||||||
|
p2.rollMany(6)
|
||||||
|
|
||||||
|
game = Game(p1, p2)
|
||||||
|
game.determineWinner()
|
47
gcse computer science/year 10/oop dice/OOP Dice.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
class Dice:
|
||||||
|
# Initialise the class - make the default amount of sides 6
|
||||||
|
def __init__(self, sides=6):
|
||||||
|
self.sides = sides
|
||||||
|
|
||||||
|
# Roll the dice once - return an integer
|
||||||
|
def roll(self):
|
||||||
|
return randint(1, self.sides)
|
||||||
|
|
||||||
|
# Roll the dice a specified amount of times - return an array of integers
|
||||||
|
def rollMany(self, times):
|
||||||
|
res = []
|
||||||
|
for i in range(times):
|
||||||
|
num = self.roll()
|
||||||
|
res.append(num)
|
||||||
|
return res
|
||||||
|
|
||||||
|
dice = Dice() # Create an instance of the class Dice
|
||||||
|
|
||||||
|
p1 = dice.rollMany(6) # Roll 6 dice for player 1
|
||||||
|
p2 = dice.rollMany(6) # Roll 6 dice for player 2
|
||||||
|
p1score = sum(p1) # Calculate player 1's score
|
||||||
|
p2score = sum(p2) # Calculate player 2's score
|
||||||
|
|
||||||
|
# Output player 1's rolls and score for the user to see
|
||||||
|
print("Player 1 rolls ({0})".format(p1score))
|
||||||
|
|
||||||
|
for i in p1:
|
||||||
|
pos = p1.index(i) + 1
|
||||||
|
print("{0}. {1}".format(pos, i))
|
||||||
|
|
||||||
|
# Output player 2's rolls and score for the user to see
|
||||||
|
print("\nPlayer 2 rolls ({0})".format(p2score))
|
||||||
|
|
||||||
|
for i in p2:
|
||||||
|
pos = p2.index(i) + 1
|
||||||
|
print("{0}. {1}".format(pos, i))
|
||||||
|
|
||||||
|
# Determine the winner
|
||||||
|
if p1score > p2score:
|
||||||
|
print("\nPlayer 1 ({0}) wins by {1} points!".format(p1score, p1score - p2score))
|
||||||
|
elif p2score > p1score:
|
||||||
|
print("\nPlayer 2 ({0}) wins by {1} points!".format(p2score, p2score - p1score))
|
||||||
|
else:
|
||||||
|
print("\nDraw!")
|
|
@ -0,0 +1,33 @@
|
||||||
|
# read the text file
|
||||||
|
f = open('user.txt')
|
||||||
|
r = f.read()
|
||||||
|
|
||||||
|
# populate a dictionary with the data
|
||||||
|
users = {}
|
||||||
|
for i in r.split('\n'):
|
||||||
|
username = i.split(', ')[0]
|
||||||
|
password = i.split(', ')[1]
|
||||||
|
users[username] = password
|
||||||
|
|
||||||
|
# login function
|
||||||
|
def login(username, password):
|
||||||
|
if username in users.keys() and users[username] == password:
|
||||||
|
print('Yes!')
|
||||||
|
else:
|
||||||
|
print('No!')
|
||||||
|
|
||||||
|
# password validation
|
||||||
|
def validatePassword(password):
|
||||||
|
errors = []
|
||||||
|
password = str(password)
|
||||||
|
if len(password) < 8:
|
||||||
|
errors.append('Your password is not long enough! It must be a minimum of eight chracters.')
|
||||||
|
if any(i.islower() for i in password) == False:
|
||||||
|
errors.append('Your password does not include a lower case letter!')
|
||||||
|
if any(i.isupper() for i in password) == False:
|
||||||
|
errors.append('Your password does not include a upper case letter!')
|
||||||
|
print(errors)
|
||||||
|
|
||||||
|
validatePassword('hi')
|
||||||
|
validatePassword('ajsggfhgshjgGFSAFJGFG')
|
||||||
|
validatePassword('HELLO')
|
3
gcse computer science/year 10/password reset/user.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
lSpratt45, goldfish
|
||||||
|
mTaylor2, p@ssword
|
||||||
|
eKelly31, l£tMe!n
|
|
@ -0,0 +1,200 @@
|
||||||
|
import math, random, pygame, sys
|
||||||
|
|
||||||
|
# Game class
|
||||||
|
class Game():
|
||||||
|
def __init__(self):
|
||||||
|
self.score = 0
|
||||||
|
self.raspberryCount = 0
|
||||||
|
|
||||||
|
# Turret class
|
||||||
|
class Turret(pygame.sprite.Sprite):
|
||||||
|
def __init__(self):
|
||||||
|
pygame.sprite.Sprite.__init__(self) # extend the pygame Sprite class
|
||||||
|
self.image = pygame.image.load('turret.png')
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect.x = 240
|
||||||
|
self.rect.y = 630
|
||||||
|
|
||||||
|
# Method that enables the turret to move
|
||||||
|
def move(self, direction):
|
||||||
|
if direction == 'left' and self.rect.x > 5:
|
||||||
|
self.rect.x -= 5
|
||||||
|
if direction == 'right' and self.rect.x < (480 - self.rect.width):
|
||||||
|
self.rect.x += 5
|
||||||
|
|
||||||
|
# Bullet class
|
||||||
|
class Bullet(pygame.sprite.Sprite):
|
||||||
|
def __init__(self, turret):
|
||||||
|
pygame.sprite.Sprite.__init__(self) # extend the pygame Sprite class
|
||||||
|
self.image = pygame.image.load('bullet.png')
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect.x = turret.rect.x + (turret.rect.width / 2) - (self.rect.width / 2)
|
||||||
|
self.rect.y = turret.rect.y - turret.rect.height
|
||||||
|
|
||||||
|
# Method that moves bullets up the screen
|
||||||
|
def updatePosition(self):
|
||||||
|
if self.rect.y > 0 - self.rect.height: # ensures that the bullet is on the screen
|
||||||
|
self.rect.y -= 5
|
||||||
|
else:
|
||||||
|
self.kill() # remove the bullet when it goes off of the screen
|
||||||
|
|
||||||
|
# Fruit class
|
||||||
|
class Fruit(pygame.sprite.Sprite):
|
||||||
|
def __init__(self):
|
||||||
|
pygame.sprite.Sprite.__init__(self)
|
||||||
|
|
||||||
|
# Determine the type of fruit it will be
|
||||||
|
self.genus = random.randint(1, 3)
|
||||||
|
|
||||||
|
if self.genus == 1: imageFile = 'raspberry'
|
||||||
|
elif self.genus == 2: imageFile = 'strawberry'
|
||||||
|
elif self.genus == 3: imageFile = 'cherry'
|
||||||
|
|
||||||
|
self.image = pygame.image.load('{0}.png'.format(imageFile)) # load the type of fruit
|
||||||
|
self.image = pygame.transform.rotate(self.image, -15 + random.randint(0, 20)) # rotate the fruit
|
||||||
|
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect.y = 0 - self.rect.height
|
||||||
|
self.rect.x = random.randint(2, 44) * 10
|
||||||
|
|
||||||
|
# Method that moves fruit down the screen
|
||||||
|
def updatePosition(self, game):
|
||||||
|
if self.rect.y < 640: # ensures that the fruit is on the screen
|
||||||
|
self.rect.y += 3
|
||||||
|
else:
|
||||||
|
if self.genus == 1: # if the fruit was a raspberry
|
||||||
|
game.score += 10 # add 10 points
|
||||||
|
game.raspberryCount += 1 # increase raspberry count
|
||||||
|
else: # otherwise
|
||||||
|
game.score -= 50 # remove 50 points
|
||||||
|
self.kill() # remove the fruit
|
||||||
|
|
||||||
|
# Method to update score and remove fruit when shot
|
||||||
|
def shot(self, game, bullet):
|
||||||
|
if self.genus == 1:
|
||||||
|
game.score -= 50
|
||||||
|
game.raspberryCount += 1
|
||||||
|
else:
|
||||||
|
game.score += 10
|
||||||
|
self.kill()
|
||||||
|
bullet.kill()
|
||||||
|
|
||||||
|
# Bullet timeout function
|
||||||
|
keyTimeout = {}
|
||||||
|
def keyPressed(keys, key, timeout):
|
||||||
|
if keys[key] == False:
|
||||||
|
return False
|
||||||
|
|
||||||
|
currentTime = pygame.time.get_ticks()
|
||||||
|
|
||||||
|
if key in keyTimeout and keyTimeout[key] > currentTime:
|
||||||
|
return False
|
||||||
|
|
||||||
|
keyTimeout[key] = currentTime + timeout
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Initialise the game
|
||||||
|
pygame.init()
|
||||||
|
pygame.key.set_repeat(1, 20)
|
||||||
|
scoreFont = pygame.font.Font(None, 17) # set the score font
|
||||||
|
statusFont = pygame.font.Font(None, 17) # set the status font
|
||||||
|
black = (0, 0, 0) # rgb for black
|
||||||
|
screen = pygame.display.set_mode([480, 640]) # set the size of the window
|
||||||
|
pygame.display.set_caption('Raspberry Pie') # set the title of the window
|
||||||
|
|
||||||
|
# Create initial object instances
|
||||||
|
game = Game()
|
||||||
|
turret = Turret()
|
||||||
|
fruits = pygame.sprite.Group()
|
||||||
|
bullets = pygame.sprite.Group()
|
||||||
|
|
||||||
|
sprites = pygame.sprite.Group()
|
||||||
|
sprites.add(turret)
|
||||||
|
|
||||||
|
# Initialize game over flag and timer
|
||||||
|
endGame = False
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
tock = 0
|
||||||
|
|
||||||
|
# Game loop
|
||||||
|
while endGame == False:
|
||||||
|
clock.tick(30)
|
||||||
|
tock += 1
|
||||||
|
screen.fill(black)
|
||||||
|
|
||||||
|
# Process events
|
||||||
|
for event in pygame.event.get():
|
||||||
|
# Handle exiting
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Handle key presses
|
||||||
|
keys = pygame.key.get_pressed()
|
||||||
|
|
||||||
|
# If the key was the left arrow
|
||||||
|
if keys[pygame.K_LEFT]:
|
||||||
|
turret.move('left')
|
||||||
|
# If the key was the right arrow
|
||||||
|
if keys[pygame.K_RIGHT]:
|
||||||
|
turret.move('right')
|
||||||
|
# If the key was the space key
|
||||||
|
if keyPressed(keys, pygame.K_SPACE, 1000):
|
||||||
|
bullet = Bullet(turret)
|
||||||
|
bullets.add(bullet)
|
||||||
|
# If the key was the escape key
|
||||||
|
if keys[pygame.K_ESCAPE]:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Move objects
|
||||||
|
for bullet in bullets:
|
||||||
|
bullet.updatePosition()
|
||||||
|
for fruit in fruits:
|
||||||
|
fruit.updatePosition(game)
|
||||||
|
|
||||||
|
# Add new fruit if two seconds has elapsed
|
||||||
|
if tock > 60:
|
||||||
|
if len(fruits) < 10: # cap the amount of fruits to be less than 10
|
||||||
|
fruit = Fruit()
|
||||||
|
fruits.add(fruit)
|
||||||
|
tock = 0 # reset counter
|
||||||
|
|
||||||
|
# Check for collisions
|
||||||
|
collisions = pygame.sprite.groupcollide(fruits, bullets, False, True)
|
||||||
|
|
||||||
|
if collisions:
|
||||||
|
for fruit in collisions:
|
||||||
|
fruit.shot(game, collisions[fruit][0])
|
||||||
|
|
||||||
|
# Update player score
|
||||||
|
scoreText = scoreFont.render('Score: {0}'.format(str(game.score)), True, (255, 255, 255), (0, 0, 0))
|
||||||
|
screen.blit(scoreText, (0, 620)) # put the score onto the screen at 0, 620
|
||||||
|
|
||||||
|
statusText = statusFont.render('Raspberries: {0}'.format(str(10 - game.raspberryCount)), True, (255, 210, 210), (0, 0, 0))
|
||||||
|
screen.blit(statusText, (0, 10))
|
||||||
|
|
||||||
|
# Update the screen and check for game over
|
||||||
|
sprites.draw(screen)
|
||||||
|
bullets.draw(screen)
|
||||||
|
fruits.draw(screen)
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
if game.raspberryCount >= 10:
|
||||||
|
endGame = True
|
||||||
|
|
||||||
|
|
||||||
|
# Game over: display the player's final score
|
||||||
|
scoreBadge = pygame.image.load('scoreframe.png')
|
||||||
|
scoreBadge.convert_alpha()
|
||||||
|
screen.blit(scoreBadge, (90, 250))
|
||||||
|
|
||||||
|
scoreFont = pygame.font.Font(None, 52)
|
||||||
|
statusText = scoreFont.render('Your Score: {0}'.format(str(game.score)), True, (0, 0, 0), (231, 230, 33))
|
||||||
|
screen.blit(statusText, (105, 300))
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
# Wait for the player to close the game window
|
||||||
|
while True:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
sys.exit()
|
|
@ -0,0 +1,181 @@
|
||||||
|
import math, random, pygame, sys
|
||||||
|
|
||||||
|
# Game class
|
||||||
|
class Game():
|
||||||
|
def __init__(self):
|
||||||
|
self.score = 0
|
||||||
|
self.raspberryCount = 0
|
||||||
|
|
||||||
|
# Turret class
|
||||||
|
class Turret(pygame.sprite.Sprite):
|
||||||
|
def __init__(self):
|
||||||
|
pygame.sprite.Sprite.__init__(self) # extend the pygame Sprite class
|
||||||
|
self.image = pygame.image.load('turret.png')
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect.x = 240
|
||||||
|
self.rect.y = 630
|
||||||
|
|
||||||
|
# Method that enables the turret to move
|
||||||
|
def move(self, direction):
|
||||||
|
if direction == 'left' and self.rect.x > 5:
|
||||||
|
self.rect.x -= 5
|
||||||
|
if direction == 'right' and self.rect.x < (480 - self.rect.width):
|
||||||
|
self.rect.x += 5
|
||||||
|
|
||||||
|
# Bullet class
|
||||||
|
class Bullet(pygame.sprite.Sprite):
|
||||||
|
def __init__(self, turret):
|
||||||
|
pygame.sprite.Sprite.__init__(self) # extend the pygame Sprite class
|
||||||
|
self.image = pygame.image.load('bullet.png')
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect.x = turret.rect.x + (turret.rect.width / 2) - (self.rect.width / 2)
|
||||||
|
self.rect.y = turret.rect.y - turret.rect.height
|
||||||
|
|
||||||
|
# Method that moves bullets up the screen
|
||||||
|
def updatePosition(self):
|
||||||
|
if self.rect.y > 0 - self.rect.height: # ensures that the bullet is on the screen
|
||||||
|
self.rect.y -= 5
|
||||||
|
else:
|
||||||
|
self.kill() # remove the bullet when it goes off of the screen
|
||||||
|
|
||||||
|
# Fruit class
|
||||||
|
class Fruit(pygame.sprite.Sprite):
|
||||||
|
def __init__(self):
|
||||||
|
pygame.sprite.Sprite.__init__(self)
|
||||||
|
|
||||||
|
# Determine the type of fruit it will be
|
||||||
|
self.genus = random.randint(1, 3)
|
||||||
|
|
||||||
|
if self.genus == 1: imageFile = 'raspberry'
|
||||||
|
elif self.genus == 2: imageFile = 'strawberry'
|
||||||
|
elif self.genus == 3: imageFile = 'cherry'
|
||||||
|
|
||||||
|
self.image = pygame.image.load('{0}.png'.format(imageFile)) # load the type of fruit
|
||||||
|
self.image = pygame.transform.rotate(self.image, -15 + random.randint(0, 20)) # rotate the fruit
|
||||||
|
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect.y = 0 - self.rect.height
|
||||||
|
self.rect.x = random.randint(2, 44) * 10
|
||||||
|
|
||||||
|
# Method that moves fruit down the screen
|
||||||
|
def updatePosition(self, game):
|
||||||
|
if self.rect.y < 640: # ensures that the fruit is on the screen
|
||||||
|
self.rect.y += 3
|
||||||
|
else:
|
||||||
|
if self.genus == 1: # if the fruit was a raspberry
|
||||||
|
game.score += 10 # add 10 points
|
||||||
|
game.raspberryCount += 1 # increase raspberry count
|
||||||
|
else: # otherwise
|
||||||
|
game.score -= 50 # remove 50 points
|
||||||
|
self.kill() # remove the fruit
|
||||||
|
|
||||||
|
# Method to update score and remove fruit when shot
|
||||||
|
def shot(self, game):
|
||||||
|
if self.genus == 1:
|
||||||
|
game.score -= 50
|
||||||
|
game.raspberryCount += 1
|
||||||
|
else:
|
||||||
|
game.score += 10
|
||||||
|
self.kill()
|
||||||
|
|
||||||
|
# Initialise the game
|
||||||
|
pygame.init()
|
||||||
|
pygame.key.set_repeat(1, 20)
|
||||||
|
scoreFont = pygame.font.Font(None, 17) # set the score font
|
||||||
|
statusFont = pygame.font.Font(None, 17) # set the status font
|
||||||
|
black = (0, 0, 0) # rgb for black
|
||||||
|
screen = pygame.display.set_mode([480, 640]) # set the size of the window
|
||||||
|
pygame.display.set_caption('Raspberry Pie') # set the title of the window
|
||||||
|
|
||||||
|
# Create initial object instances
|
||||||
|
game = Game()
|
||||||
|
turret = Turret()
|
||||||
|
fruits = pygame.sprite.Group()
|
||||||
|
bullets = pygame.sprite.Group()
|
||||||
|
|
||||||
|
sprites = pygame.sprite.Group()
|
||||||
|
sprites.add(turret)
|
||||||
|
|
||||||
|
# Initialize game over flag and timer
|
||||||
|
endGame = False
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
tock = 0
|
||||||
|
|
||||||
|
# Game loop
|
||||||
|
while endGame == False:
|
||||||
|
clock.tick(30)
|
||||||
|
tock += 1
|
||||||
|
screen.fill(black)
|
||||||
|
|
||||||
|
# Process events
|
||||||
|
for event in pygame.event.get():
|
||||||
|
# Handle exiting
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Handle key down
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
# If the key was the left arrow
|
||||||
|
if event.key == pygame.K_LEFT:
|
||||||
|
turret.move('left')
|
||||||
|
# If the key was the right arrow
|
||||||
|
if event.key == pygame.K_RIGHT:
|
||||||
|
turret.move('right')
|
||||||
|
# If the key was the space key
|
||||||
|
if event.key == pygame.K_SPACE:
|
||||||
|
bullet = Bullet(turret)
|
||||||
|
bullets.add(bullet)
|
||||||
|
|
||||||
|
# Move objects
|
||||||
|
for bullet in bullets:
|
||||||
|
bullet.updatePosition()
|
||||||
|
for fruit in fruits:
|
||||||
|
fruit.updatePosition(game)
|
||||||
|
|
||||||
|
# Add new fruit if two seconds has elapsed
|
||||||
|
if tock > 60:
|
||||||
|
if len(fruits) < 10: # cap the amount of fruits to be less than 10
|
||||||
|
fruit = Fruit()
|
||||||
|
fruits.add(fruit)
|
||||||
|
tock = 0 # reset counter
|
||||||
|
|
||||||
|
# Check for collisions
|
||||||
|
collisions = pygame.sprite.groupcollide(fruits, bullets, False, True)
|
||||||
|
|
||||||
|
if collisions:
|
||||||
|
for fruit in collisions:
|
||||||
|
fruit.shot(game)
|
||||||
|
|
||||||
|
# Update player score
|
||||||
|
scoreText = scoreFont.render('Score: {0}'.format(str(game.score)), True, (255, 255, 255), (0, 0, 0))
|
||||||
|
screen.blit(scoreText, (0, 620)) # put the score onto the screen at 0, 620
|
||||||
|
|
||||||
|
statusText = statusFont.render('Raspberries: {0}'.format(str(10 - game.raspberryCount)), True, (255, 210, 210), (0, 0, 0))
|
||||||
|
screen.blit(statusText, (0, 10))
|
||||||
|
|
||||||
|
# Update the screen and check for game over
|
||||||
|
sprites.draw(screen)
|
||||||
|
bullets.draw(screen)
|
||||||
|
fruits.draw(screen)
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
if game.raspberryCount >= 10:
|
||||||
|
endGame = True
|
||||||
|
|
||||||
|
|
||||||
|
# Game over: display the player's final score
|
||||||
|
scoreBadge = pygame.image.load('scoreframe.png')
|
||||||
|
scoreBadge.convert_alpha()
|
||||||
|
screen.blit(scoreBadge, (90, 250))
|
||||||
|
|
||||||
|
scoreFont = pygame.font.Font(None, 52)
|
||||||
|
statusText = scoreFont.render('Your Score: {0}'.format(str(game.score)), True, (0, 0, 0), (231, 230, 33))
|
||||||
|
screen.blit(statusText, (105, 300))
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
# Wait for the player to close the game window
|
||||||
|
while True:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
sys.exit()
|
BIN
gcse computer science/year 10/raspberry pie game/bullet.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
gcse computer science/year 10/raspberry pie game/cherry.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
gcse computer science/year 10/raspberry pie game/raspberry.png
Normal file
After Width: | Height: | Size: 1 KiB |
BIN
gcse computer science/year 10/raspberry pie game/scoreframe.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
gcse computer science/year 10/raspberry pie game/strawberry.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
gcse computer science/year 10/raspberry pie game/turret.png
Normal file
After Width: | Height: | Size: 333 B |
|
@ -0,0 +1,14 @@
|
||||||
|
word = input('Please enter a word!')
|
||||||
|
|
||||||
|
def isPallindrome(x):
|
||||||
|
reverse = ''
|
||||||
|
i = len(x)
|
||||||
|
while i > 0:
|
||||||
|
reverse += x[i - 1]
|
||||||
|
i = i - 1
|
||||||
|
return x == reverse
|
||||||
|
|
||||||
|
if isPallindrome(word):
|
||||||
|
print('{0} is a pallindrome!'.format(word))
|
||||||
|
else:
|
||||||
|
print('{0} is not a pallindrome!'.format(word))
|
|
@ -0,0 +1,15 @@
|
||||||
|
word = input('Please enter a word!')
|
||||||
|
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
|
||||||
|
nopunc = ''
|
||||||
|
|
||||||
|
for i in word:
|
||||||
|
if i not in punctuations:
|
||||||
|
nopunc = nopunc + i
|
||||||
|
|
||||||
|
def isPallindrome(x):
|
||||||
|
return x == x[::-1]
|
||||||
|
|
||||||
|
if isPallindrome(nopunc):
|
||||||
|
print('{0} is a pallindrome!'.format(word))
|
||||||
|
else:
|
||||||
|
print('{0} is not a pallindrome!'.format(word))
|
|
@ -0,0 +1,9 @@
|
||||||
|
word = input('Please enter a word!')
|
||||||
|
|
||||||
|
def isPallindrome(x):
|
||||||
|
return x == x[::-1]
|
||||||
|
|
||||||
|
if isPallindrome(word):
|
||||||
|
print('{0} is a pallindrome!'.format(word))
|
||||||
|
else:
|
||||||
|
print('{0} is not a pallindrome!'.format(word))
|
BIN
gcse computer science/year 9/html css js/eco fest/Eco Fest.pptx
Normal file
BIN
gcse computer science/year 9/html css js/eco fest/Review.docx
Normal file
BIN
gcse computer science/year 9/html css js/eco fest/Site Map.png
Normal file
After Width: | Height: | Size: 43 KiB |
BIN
gcse computer science/year 9/html css js/eco fest/Test Table.doc
Normal file
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 799 KiB |
After Width: | Height: | Size: 827 KiB |
After Width: | Height: | Size: 834 KiB |
After Width: | Height: | Size: 832 KiB |
|
@ -0,0 +1,34 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<!-- CSS and Favicon -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="stylesheet.css">
|
||||||
|
|
||||||
|
<!-- Metadata -->
|
||||||
|
<title>Ecofest</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a href="index.html"><img src="./assets/img/arrow.png" alt="" class="back"></a>
|
||||||
|
|
||||||
|
<h1 class="title">Our Acts</h1>
|
||||||
|
|
||||||
|
<div class="acts">
|
||||||
|
<div class="act">
|
||||||
|
<img src="./assets/img/everyones-environment.jpg" alt="Everyone's Environment" />
|
||||||
|
<p>Everyone's Environment</p>
|
||||||
|
</div>
|
||||||
|
<div class="act">
|
||||||
|
<img src="./assets/img/solar-drum.jpg" alt="Solar Drum" />
|
||||||
|
<p>Solar Drum</p>
|
||||||
|
</div>
|
||||||
|
<div class="act">
|
||||||
|
<img src="./assets/img/green-gizmos.jpg" alt="Green Gizmos" />
|
||||||
|
<p>Green Gizmos</p>
|
||||||
|
</div>
|
||||||
|
<div class="act">
|
||||||
|
<img src="./assets/img/john-alfred.jpg" alt="DJ John Alfred" />
|
||||||
|
<p>DJ John Alfred</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 1 MiB |
After Width: | Height: | Size: 543 KiB |
After Width: | Height: | Size: 7.5 KiB |
After Width: | Height: | Size: 81 KiB |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 1 MiB |
|
@ -0,0 +1,18 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<!-- CSS and Favicon -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="stylesheet.css">
|
||||||
|
|
||||||
|
<!-- Metadata -->
|
||||||
|
<title>Ecofest</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 class="title home">Ecofest</h1>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
Ecofest is the environmentally-friendly music festival, taking place on the <strong>4-5th April, 2020</strong>.
|
||||||
|
Find out about our acts <a href="acts.html">here</a>, get your tickets <a href="">here</a>, learn about how we're helping the environment <a href="">here</a>, and contact us <a href="">here</a>.
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* Import "Bebas Neue" and "Open Sans" fonts from Google Fonts */
|
||||||
|
@import url('https://fonts.googleapis.com/css?family=Bebas+Neue|Open+Sans&display=swap');
|
||||||
|
|
||||||
|
/* Simple browser reset */
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
/* Make the background never repeat and be centered at all times */
|
||||||
|
background-image: url("./assets/img/bg.png");
|
||||||
|
background-position: center center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-attachment: fixed;
|
||||||
|
background-size: cover;
|
||||||
|
|
||||||
|
/* Set a background colour to be displayed whilst the image is loading on slow connections */
|
||||||
|
background-color: #212121;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Base title styles */
|
||||||
|
.title {
|
||||||
|
color: #7ed957;
|
||||||
|
font-family: 'Bebas Neue', cursive;
|
||||||
|
font-size: 132px;
|
||||||
|
margin-top: 75px;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Home page specific styles for the title class */
|
||||||
|
.title.home {
|
||||||
|
margin-left: 1050px;
|
||||||
|
margin-top: 325px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styles for the green content box used on most pages */
|
||||||
|
.content {
|
||||||
|
background-color: #7ed957;
|
||||||
|
color: #212121;
|
||||||
|
font-family: 'Open Sans', sans-serif;
|
||||||
|
font-size: 24px;
|
||||||
|
padding: 20px;
|
||||||
|
margin-right: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styling to make hyperlinks orange and bold */
|
||||||
|
a {
|
||||||
|
color: #FF5722;
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styling to underline hyperlinks when they are hovered over */
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styling for the svg of the back button, displayed on all pages
|
||||||
|
exluding the home page */
|
||||||
|
.back {
|
||||||
|
height: 125px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styling that will get applied to both the back button and the title
|
||||||
|
on every page, except from the home page. */
|
||||||
|
.back && .title && :not(.home) {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styling for the array of acts displayed on the acts page */
|
||||||
|
.acts {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styling for each induvidual act within the acts array */
|
||||||
|
.act {
|
||||||
|
|
||||||
|
}
|
BIN
gcse computer science/year 9/html css js/eco fest/Workplan.docx
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
@import url('https://fonts.googleapis.com/css?family=Open+Sans|Playfair+Display&display=swap');
|
||||||
|
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
background-color: #000000;
|
||||||
|
color: #ffffff;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2 { font-family: 'Playfair Display', serif; }
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 48px;
|
||||||
|
margin-bottom: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
font-family: 'Open Sans', sans-serif;
|
||||||
|
font-weight: light;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav {
|
||||||
|
list-style-type: none;
|
||||||
|
overflow: hidden;
|
||||||
|
margin-bottom: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav li {
|
||||||
|
float: right;
|
||||||
|
font-size: 18px;
|
||||||
|
font-family: 'Open Sans', sans-serif;
|
||||||
|
margin-top: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav a {
|
||||||
|
display: block;
|
||||||
|
color: white;
|
||||||
|
text-align: center;
|
||||||
|
text-decoration: none;
|
||||||
|
padding: 14px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :not(.left) a:hover {
|
||||||
|
background-color: #ffffff;
|
||||||
|
color: #000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav li.left {
|
||||||
|
float: left;
|
||||||
|
font-size: 36px;
|
||||||
|
font-family: 'Playfair Display', serif;
|
||||||
|
margin-top: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.images { margin-top: 75px; }
|
||||||
|
|
||||||
|
div.images img {
|
||||||
|
height: 250px;
|
||||||
|
width: 250px;
|
||||||
|
margin-right: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
font-family: 'Open Sans', sans-serif;
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
background-color: #ffffff;
|
||||||
|
color: #000000;
|
||||||
|
}
|
After Width: | Height: | Size: 161 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 474 KiB |
BIN
gcse computer science/year 9/html css js/pet planet/brief.docx
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Pet Planet</title>
|
||||||
|
|
||||||
|
<link type="text/css" rel="stylesheet" href="./assets/css/index.css">
|
||||||
|
<link rel="icon" href="./assets/favicon.ico">
|
||||||
|
<style type="text/css">
|
||||||
|
p {
|
||||||
|
margin: 20px 200px 75px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="description" content="Pet Planet is a family-run pet shop located in Ashford Highstreet." />
|
||||||
|
<meta name="keywords" content="pets,dogs,cats,shop,ashford,highstreet" />
|
||||||
|
<meta name="author" content="Jacob Smith" />
|
||||||
|
<meta name="viewport" content="width=device.width, initial-scale=1.0" />
|
||||||
|
<meta property="og:title" content="Pet Planet" />
|
||||||
|
<meta property="og:description" content="Pet Planet is a family-run pet shop located in Ashford Highstreet." />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:url" content="https://pet-planet.netlify.com/" />
|
||||||
|
<meta property="og:image" content="https://pet-planet.netlify.com/assets/ogp.jpg" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav>
|
||||||
|
<li class="left"><a href="index.html">Pet Planet</a></li>
|
||||||
|
<li><a href="care.html">Care</a></li>
|
||||||
|
<li><a href="products.html">Products</a></li>
|
||||||
|
<li><a href="index.html">Home</a></li>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<h1>Caring for your pets</h1>
|
||||||
|
|
||||||
|
<h2>Cats</h2>
|
||||||
|
<p>Some essential things you must do to care for your cat include things like getting them micro-chipped, neutering them, getting them a vet plan, keeping their vaccinations up to date, getting pet insurance, and providing plenty of playtime.</p>
|
||||||
|
|
||||||
|
<h2>Dogs</h2>
|
||||||
|
<p>Some essential things you must do to care for your dog includes things like providing a clean living environment for uour dog, keeping fresh water available, giving them a quality diet, having them examined by a vet on a regular basis, provide ample opportunites to exrcise, and training them to follow simple commands.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 207 KiB |
|
@ -0,0 +1,43 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Pet Planet</title>
|
||||||
|
|
||||||
|
<link type="text/css" rel="stylesheet" href="./assets/css/index.css">
|
||||||
|
<link rel="icon" href="./assets/favicon.ico">
|
||||||
|
<style type="text/css">
|
||||||
|
.check-us-out {
|
||||||
|
margin-top: 50px;
|
||||||
|
margin-bottom: 25px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="description" content="Pet Planet is a family-run pet shop located in Ashford Highstreet." />
|
||||||
|
<meta name="keywords" content="pets,dogs,cats,shop,ashford,highstreet" />
|
||||||
|
<meta name="author" content="Jacob Smith" />
|
||||||
|
<meta name="viewport" content="width=device.width, initial-scale=1.0" />
|
||||||
|
<meta property="og:title" content="Pet Planet" />
|
||||||
|
<meta property="og:description" content="Pet Planet is a family-run pet shop located in Ashford Highstreet." />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:url" content="https://pet-planet.netlify.com/" />
|
||||||
|
<meta property="og:image" content="https://pet-planet.netlify.com/assets/ogp.jpg" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav>
|
||||||
|
<li class="left"><a href="index.html">Pet Planet</a></li>
|
||||||
|
<li><a href="care.html">Care</a></li>
|
||||||
|
<li><a href="products.html">Products</a></li>
|
||||||
|
<li><a href="index.html">Home</a></li>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<h1>Welcome to Pet Planet</h1>
|
||||||
|
<p>We are a family-run pet shop located in Ashford Highstreet.</p>
|
||||||
|
|
||||||
|
<h1 class="check-us-out">Check us out</h1>
|
||||||
|
<iframe width='250px' height='250px' id='mapcanvas' src='https://maps.google.com/maps?q=High%20Street,%20Ashford&t=&z=10&ie=UTF8&iwloc=&output=embed' frameborder='0' scrolling='no' marginheight='0' marginwidth='0'><div class="zxos8_gm"><a href="https://www.giantbomb.com/profile/mobilephones/blog/">here</a></div><div style='overflow:hidden;'><div id='gmap_canvas' style='height:100%;width:100%;'></div></div></iframe>
|
||||||
|
|
||||||
|
<br><br><br>
|
||||||
|
<a href="mailto:insertemail@here.xyz" class="contact-us">Contact us.</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,37 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Pet Planet</title>
|
||||||
|
|
||||||
|
<link type="text/css" rel="stylesheet" href="./assets/css/index.css">
|
||||||
|
<link rel="icon" href="./assets/favicon.ico">
|
||||||
|
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="description" content="Pet Planet is a family-run pet shop located in Ashford Highstreet." />
|
||||||
|
<meta name="keywords" content="pets,dogs,cats,shop,ashford,highstreet" />
|
||||||
|
<meta name="author" content="Jacob Smith" />
|
||||||
|
<meta name="viewport" content="width=device.width, initial-scale=1.0" />
|
||||||
|
<meta property="og:title" content="Pet Planet" />
|
||||||
|
<meta property="og:description" content="Pet Planet is a family-run pet shop located in Ashford Highstreet." />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:url" content="https://pet-planet.netlify.com/" />
|
||||||
|
<meta property="og:image" content="https://pet-planet.netlify.com/assets/ogp.jpg" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav>
|
||||||
|
<li class="left"><a href="index.html">Pet Planet</a></li>
|
||||||
|
<li><a href="care.html">Care</a></li>
|
||||||
|
<li><a href="products.html">Products</a></li>
|
||||||
|
<li><a href="index.html">Home</a></li>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<h1>Products</h1>
|
||||||
|
<p>We stock many high quality products in our store.<br>Check them out here.</p>
|
||||||
|
|
||||||
|
<div class="images">
|
||||||
|
<img src="./assets/img/pedigree_dogfood.jpg" alt="Pedigree Dogfood">
|
||||||
|
<img src="./assets/img/splaker_leash.jpg" alt="Splaker Dog Leash">
|
||||||
|
<img src="./assets/img/mouse_toy.jpg" alt="Mouse Toy">
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
gcse computer science/year 9/microbit/1/1.png
Normal file
After Width: | Height: | Size: 37 KiB |
13992
gcse computer science/year 9/microbit/1/microbit-Scrolling-Text.hex
Normal file
BIN
gcse computer science/year 9/microbit/10/10.png
Normal file
After Width: | Height: | Size: 589 KiB |
BIN
gcse computer science/year 9/microbit/11/11.png
Normal file
After Width: | Height: | Size: 202 KiB |
14028
gcse computer science/year 9/microbit/11/microbit-Coin-Toss.hex
Normal file
BIN
gcse computer science/year 9/microbit/12/12.png
Normal file
After Width: | Height: | Size: 299 KiB |
14037
gcse computer science/year 9/microbit/12/microbit-Love-o-meter.hex
Normal file
BIN
gcse computer science/year 9/microbit/2/bikelight.png
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
gcse computer science/year 9/microbit/2/lighthouse.png
Normal file
After Width: | Height: | Size: 70 KiB |
14004
gcse computer science/year 9/microbit/2/microbit-Bike-Light.hex
Normal file
14004
gcse computer science/year 9/microbit/2/microbit-Lighthouse.hex
Normal file
14035
gcse computer science/year 9/microbit/2/microbit-SOS-Message.hex
Normal file
BIN
gcse computer science/year 9/microbit/2/sos.png
Normal file
After Width: | Height: | Size: 359 KiB |
0
gcse computer science/year 9/microbit/3/3.png
Normal file
14006
gcse computer science/year 9/microbit/3/microbit-Creeper.hex
Normal file
BIN
gcse computer science/year 9/microbit/4/4.png
Normal file
After Width: | Height: | Size: 209 KiB |
14019
gcse computer science/year 9/microbit/4/microbit-Fading-Heart.hex
Normal file
BIN
gcse computer science/year 9/microbit/5/5.png
Normal file
After Width: | Height: | Size: 148 KiB |
BIN
gcse computer science/year 9/microbit/6/6.png
Normal file
After Width: | Height: | Size: 210 KiB |
14040
gcse computer science/year 9/microbit/6/microbit-Scoring.hex
Normal file
BIN
gcse computer science/year 9/microbit/7/7.png
Normal file
After Width: | Height: | Size: 102 KiB |
14030
gcse computer science/year 9/microbit/7/microbit-Dice.hex
Normal file
BIN
gcse computer science/year 9/microbit/8/8.png
Normal file
After Width: | Height: | Size: 257 KiB |
14026
gcse computer science/year 9/microbit/8/microbit-Fading-Heart-2.hex
Normal file
BIN
gcse computer science/year 9/microbit/9/9.png
Normal file
After Width: | Height: | Size: 442 KiB |
14034
gcse computer science/year 9/microbit/9/microbit-Fading-Heart-3.hex
Normal file
BIN
gcse computer science/year 9/microbit/Microbit.docx
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
counter = 26
|
||||||
|
ciphertext = input('Please input some ciphertext to decrypt.')
|
||||||
|
ciphertext = ciphertext.upper()
|
||||||
|
|
||||||
|
while counter >= 0:
|
||||||
|
outputWord = ''
|
||||||
|
|
||||||
|
for i in ciphertext:
|
||||||
|
asc = ord(i)
|
||||||
|
shiftChr = asc + counter
|
||||||
|
|
||||||
|
if shiftChr >= 90:
|
||||||
|
shiftChr = (shiftChr-90)+64
|
||||||
|
|
||||||
|
outputWord = outputWord + chr(shiftChr)
|
||||||
|
|
||||||
|
print(outputWord)
|
||||||
|
counter = counter - 1
|
|
@ -0,0 +1,12 @@
|
||||||
|
output = ''
|
||||||
|
asc = 0
|
||||||
|
|
||||||
|
msg = input('Please input the text.')
|
||||||
|
key = input('How many characters would you like to shift that text by?')
|
||||||
|
|
||||||
|
for i in msg:
|
||||||
|
asc = ord(i)
|
||||||
|
shiftChr = asc + int(key)
|
||||||
|
output = output + chr(shiftChr)
|
||||||
|
|
||||||
|
print(output)
|
|
@ -0,0 +1,65 @@
|
||||||
|
import math
|
||||||
|
import string
|
||||||
|
import re
|
||||||
|
|
||||||
|
def encryptChar(char, key):
|
||||||
|
# check if the character is a letter
|
||||||
|
if re.match('^[a-zA-Z]*$', char):
|
||||||
|
# figure out the position of the character in the alphabet
|
||||||
|
position = string.ascii_lowercase.index(char.lower()) + 1
|
||||||
|
# encrypt the character
|
||||||
|
return math.ceil((position ** 2) + int(key))
|
||||||
|
# if the character is not a letter, just return it
|
||||||
|
else:
|
||||||
|
return char
|
||||||
|
|
||||||
|
def encrypt(text, key):
|
||||||
|
# split the string into a list of characters and replace spaces with ||
|
||||||
|
characters = [w.replace(' ', '||') for w in [char for char in text]]
|
||||||
|
# encrypt the message and return it
|
||||||
|
return ' '.join(map(str, [encryptChar(x, key) for x in characters]))
|
||||||
|
|
||||||
|
def decryptChar(char, key):
|
||||||
|
# check if the character is a number
|
||||||
|
if re.match('^[0-9]*$', char):
|
||||||
|
# create a dictionary with all of the lower case letters
|
||||||
|
d = dict(enumerate(string.ascii_lowercase, 1))
|
||||||
|
# return the letter in the index of the resulting number
|
||||||
|
return d[math.sqrt(int(char) - int(key))]
|
||||||
|
# return || as a space
|
||||||
|
if char == '||':
|
||||||
|
return ' '
|
||||||
|
# if the character is not a number or ||, just return it
|
||||||
|
else: return char
|
||||||
|
|
||||||
|
|
||||||
|
def decrypt(text, key):
|
||||||
|
# split the string into a list
|
||||||
|
characters = text.split()
|
||||||
|
# decrypt the message and return it
|
||||||
|
return ''.join([decryptChar(x, key) for x in characters])
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
inp = input('Welcome to Enkodo!\nWhat would you like to do?\n\n1) Encrypt a message\n2) Decrypt a code\n3) Exit\nYour choice: ')
|
||||||
|
|
||||||
|
if inp == '1':
|
||||||
|
msg = input('\nPlease input the message you would like to encrypt:\n')
|
||||||
|
key = input('\nPlease provide a key to encrypt that with.\n')
|
||||||
|
encrypted = encrypt(msg, key)
|
||||||
|
|
||||||
|
print('\nYour message has been successfully encrypted. Here it is!\n')
|
||||||
|
print(encrypted)
|
||||||
|
exit()
|
||||||
|
if inp == '2':
|
||||||
|
code = input('\nPlease input the code you would like to decrypt:\n')
|
||||||
|
key = input('\nWhat was the key the code was encrypted with?\n')
|
||||||
|
decrypted = decrypt(code, key)
|
||||||
|
|
||||||
|
print('\nYour message has been successfully decrypted. Here it is!\n')
|
||||||
|
print(decrypted)
|
||||||
|
exit()
|
||||||
|
if inp == '3':
|
||||||
|
print('\nGoodbye!')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
menu()
|
|
@ -0,0 +1,2 @@
|
||||||
|
age = input('What is your age?')
|
||||||
|
print('Your age is ' + age)
|
|
@ -0,0 +1,24 @@
|
||||||
|
import random
|
||||||
|
|
||||||
|
# 0: rock
|
||||||
|
# 1: paper
|
||||||
|
# 2: scissors
|
||||||
|
rps = ['rock', 'paper', 'scissors']
|
||||||
|
|
||||||
|
cpu = random.randint(0, 2)
|
||||||
|
|
||||||
|
user = str.lower(input('Rock, paper, or scissors?'))
|
||||||
|
user = rps.index(user)
|
||||||
|
|
||||||
|
print('Computer: ', rps[cpu])
|
||||||
|
print('User: ', rps[user])
|
||||||
|
|
||||||
|
# if it is a tie
|
||||||
|
if ((cpu == 0) & (user == 0)) | ((cpu == 1) & (user == 1)) | ((cpu == 2) & (user == 2)):
|
||||||
|
print('It was a tie!')
|
||||||
|
exit()
|
||||||
|
# if the computer wins
|
||||||
|
elif ((cpu == 1) & (user == 0)) | ((cpu == 0) & (user == 2)) | ((cpu == 2) & (user == 1)):
|
||||||
|
print('Computer wins!')
|
||||||
|
else:
|
||||||
|
print('User wins!')
|
|
@ -0,0 +1,7 @@
|
||||||
|
sentence = input('Please input a sentence.')
|
||||||
|
charCount = 0
|
||||||
|
|
||||||
|
for i in sentence:
|
||||||
|
charCount = charCount + 1
|
||||||
|
|
||||||
|
print(charCount)
|
|
@ -0,0 +1 @@
|
||||||
|
print(str.upper(input('Please input a sentence.')))
|
|
@ -0,0 +1,5 @@
|
||||||
|
sentence = str(input('Please input a sentence.'))
|
||||||
|
wordToReplace = str(input('Please input a word to replace.'))
|
||||||
|
replaceWith = str(input('Please input a word to replace it with.'))
|
||||||
|
|
||||||
|
print(sentence.replace(wordToReplace, replaceWith))
|
|
@ -0,0 +1,9 @@
|
||||||
|
sentence = str(input('Please input a sentence.'))
|
||||||
|
words = sentence.split()
|
||||||
|
theCount = 0
|
||||||
|
|
||||||
|
for word in words:
|
||||||
|
if str.lower(word) == 'the':
|
||||||
|
theCount = theCount + 1
|
||||||
|
|
||||||
|
print('"The" appears ', theCount, " times.")
|