Upload Python Files

This commit is contained in:
Ray 2023-09-17 17:04:52 +10:00
commit 08f80bfc0f
6 changed files with 283 additions and 0 deletions

30
Session 1 – 28-04-22.py Normal file
View File

@ -0,0 +1,30 @@
# Introduction
print ("Hello World!!!!")
print ("My name is Rayyan and I like coding!!!!")
print ("Wow we like CTRL+D!")
# Activity 1 - Write a program to print the following
print ("Rayyan Hodges")
print ("Blue")
print ("Breaking Bad/Better Call Saul")
# Activity 2 - Try the following program
print ("it has been \n such a lovely day \n today because \n I have started to code \n in Python")
# Activity 3 - How to make a cup of tea instructions
print ("Fill the jug with water")
print ("Boil the jug")
print ("Get a cup")
print ("Put a tea bag in the cup")
print ("Add the boiling water to the cup")
print ("Add some milk")
print ("Add two teaspoons of sugar")
print ("Use a spoon to stir")
print ("enjoy")
# Activity 4 - Create Tree Pattern
print (" X")
print (" XXX")
print (" XXXXX")
print ("XXXXXXX")
print (" X")
# Actvity 5 - Variable exercises
name = input ("Welcome, what is your name? ")
town = input ("Hello " + name + " where are you from?")
print (town + " that is a lovely place")

47
Session 2 - 5-05-22.py Normal file
View File

@ -0,0 +1,47 @@
# Keywords (Cannot use these within variables)
import keyword
print (keyword.kwlist)
# Python Built-In Functions
print ("Hello World")
print ("Hello, what is happening?")
z = ("pie", "cake", "sausage roll")
print(z)
print ("Hello", "how are you?", sep=" ---")
# Determining a Variable
x = "Rayyan"
print (x)
# Calculating the user's Age given their date of birth
from datetime import datetime
Year = int(input("Please enter the year you were born: "))
Month = int(input("Please imput the number of the month you were born. (For example 8 = August: "))
Day = int(input("Please enter the day you were born: "))
DateOfBirth = datetime(Year, Month, Day)
Age = datetime.now() - DateOfBirth
print("You are " + str(Age.days) + " days old")
convertdays = int(Age.days)
AgeYears = convertdays/365
print("Or " +str(AgeYears) + " years old to be less precise")
print(type(AgeYears))
# Creating a variable and using the assignment operator
NoOfItems = 5
print (NoOfItems)
# Adding another item
NoOfItems = NoOfItems + 1
print (NoOfItems)
# Reassigning a string type to NoOfItems
NoOfItems = "Six"
print(NoOfItems)
#Adds two numbers together (NOT addition)
num1=input("Enter a number between 1 and 100: ")
num2=input("Enter another number between 1 and 100: ")
print ("Number 1 + Number 2=", num1+num2)

69
Session 3 - 12-05-2022.py Normal file
View File

@ -0,0 +1,69 @@
#Example 1
x = 42 # is of type int
y = "Rayyan" # y is type of string
print(x)
print(y)
#Example 2
x = 42 # x is of type int
print(x)
x = "Arthur" # x is now type of string
print(x)
#Example 3
theMeaningOfTheUniverse = 123456789 # this variable is a bit long but good to read.
print(theMeaningOfTheUniverse)
#Example 4 - Variable intended to cause error (originally "2ndBirdType" Cannot be variable at the start. Replaced with underscore.
_2ndBirdType = "African Swallow"
print(_2ndBirdType)
#Example 5 - Creating variables to combine - concatenate
birdtype1 = "African Swallow" # This variable contains a string.
print("How fast can an unladen " + birdtype1 + " fly?")
#Example 6 - Converting interger variable to string
birdtype1 = "African Swallow" # This variable contains a string value
_indicatedAirSpeed = 12 # This variable contains an interger value.
print("The indicated air speed of an "+ birdtype1 + " is " + str(_indicatedAirSpeed) + " knots.")
#Example 7 - Running code and reviewing the result
print(3+2)
print(320+12553212)
print(3-2)
print(3*2)
print(55/3)
print(55%3)
print(3**3)
print(5//2)
print(5//3)
print((5+7) * (22-3) * (3/9))
#Example 8 - Determining if a users mathematical imput is even or odd.
usersNumber = int(input("Please enter a number "))
if (usersNumber % 2) == 0:
print("Thanks! Your number is even.")
else:
print("Thanks! Your number is odd.")
#Example 9 - Exploring Comparison Operators
x=5
y=9
#Check if y is greater than x
print("x > is ", x > y)
#Check if y is less than x
print("x < y is ", x <y)
#Now check if x and y are equal
print("x == y is ", x == y)
#Check if x and y are not equal
print("x != y is ", x != y)
#Check if x is greater than or equal to y
print("x >= y is ", x >= y)
#Check if x is less than or equal to y
print("x <= y is ", x <= y)

52
Session 4 - 19-05-2022.py Normal file
View File

@ -0,0 +1,52 @@
#Excercise 1
a = 200
b = 200
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("b is not greater than a")
#Excercise 2
x = 1
if (x > 0):
a = 0
b = 1
print(a,b)
#Excercise 3
print(5 > 4)
print(10 == 10)
i = 42
print(i > 10)
j = 17
print (j <= 1)
#Excercise 4
i = 42
j = 17
if j <= i:
print("j is less than or equal to i")
#Excercise 5
subjectFinalMark=int(input("Please enter the student's subject final mark: "))
if (subjectFinalMark >= 0 and subjectFinalMark < 50):
print("The student's final grade is FAIL!")
elif (subjectFinalMark >= 50 and subjectFinalMark < 60):
print("The student's final grade is PASS!")
elif (subjectFinalMark >= 60 and subjectFinalMark < 75):
print("The student's final grade is CREDIT!")
elif (subjectFinalMark >= 65 and subjectFinalMark < 85):
print ("The student's final grade is DISTINCTION!")
elif (subjectFinalMark >= 85 and subjectFinalMark < 100):
print("The student's final grade is HIGH DISTINCTION!")
else:
print("Please enter values from 0 to 100.")

32
Session 5 - 26-05-2022.py Normal file
View File

@ -0,0 +1,32 @@
# Arrays - Temporarily adding and removing items to an array
clothes_rack = []
clothes_rack.append("dress")
clothes_rack.append("trousers")
clothes_rack.append("socks")
clothes_rack.append("skirt")
clothes_rack.append("shirt")
print(clothes_rack)
print(clothes_rack[1:3])
print(clothes_rack[1:4])
clothes_rack.extend(["t-shirt", "shoes", "cap"])
print(clothes_rack)
clothes_rack.insert(4, "gloves")
print(clothes_rack)
clothes_rack.remove("shoes")
del clothes_rack[5]
print(clothes_rack)
last_item=clothes_rack.pop()
print(last_item)
print(clothes_rack)
if "dress" in clothes_rack:
print("I have found my dress")
else:
print("I can't find my dress")
print(clothes_rack.index("gloves"))
clothes_rack.sort()
print(clothes_rack)
clothes_rack.reverse()
print(clothes_rack)
for x in clothes_rack:
print(x)

53
Session 6 - 2-06-2022.py Normal file
View File

@ -0,0 +1,53 @@
import math
a = -42
math.fabs(a)
print (a)
import math
# The .fabs() function of the math library returns the absolute value of a number.
print(math.fabs(-345))
import random
for i in range(10):
print(random.randint(1, 25))
from math import sqrt
print("Welcome to the Hypotenuse calculator!")
sideA = float(input("Please enter the lengh of side 'a': "))
sideB = float(input("Please enter the length of side 'b': "))
c = sqrt(sideA ** 2 + sideB ** 2)
print("Thank you! The length of the Hypotenuse is ", str(c))
from datetime import date
theDate = date(2019, 2, 24)
print("The date is: ", theDate)
#Passing named arguments out of order
theDate = date(day = 24, month = 2, year = 2019)
print("The date is: ", theDate)
from datetime import time
theTime = time(22, 46, 15, 200)
print("The time is ", theTime)
# Creating a date object with the value of 01/02/1961
dateofBirth = date(year=1961,month=2,day=1)
print("Your date of birth is ", dateofBirth)
yr = dateofBirth.year
mth = dateofBirth.month
dy = dateofBirth.day
print("You were born on the ", dy, "day of the ", mth, "month in the year", yr)
# returning the current date using the .today() function
todaysDate = date.today()
print("Today's date ", todaysDate)
movieName = "The Life of Brian"
print(movieName[-1])