diff --git a/.idea/Python3_labs.iml b/.idea/Python3_labs.iml index aa44535..8e5446a 100644 --- a/.idea/Python3_labs.iml +++ b/.idea/Python3_labs.iml @@ -1,8 +1,10 @@ - - + + + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e1dd729 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d410f68..d73accb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/student_exercises/DG_11_Classes_and_OOP.pptx b/student_exercises/DG_11_Classes_and_OOP.pptx new file mode 100644 index 0000000..5b5e5d0 Binary files /dev/null and b/student_exercises/DG_11_Classes_and_OOP.pptx differ diff --git a/student_exercises/Ex6.py b/student_exercises/Ex6.py new file mode 100644 index 0000000..2a11405 --- /dev/null +++ b/student_exercises/Ex6.py @@ -0,0 +1,45 @@ +#! /usr/bin/python +# Exercise 6, string formatting and regular expressions. +import re + +from labs.Ex6 import postcode + +infile = open('postcodes.txt', 'r') + +# Variables for counting valid and invalid codes (part b) +valid = 0 +invalid = 0 + +for postcode in infile: + # The variable 'postcode' contain the line read from the file. + + # Ignore empty lines. + if postcode.isspace(): continue + + # TODO (a): Remove newlines, tabs and spaces. + postcode = re.sub(r"\s+", r"", postcode) + + # TODO (a): Convert to uppercase. + postcode = postcode.upper() + + # TODO (a): Insert a space before the final digit and 2 letters. + postcode = re.sub(r"(\d[A-Z]{2})$", r" \1", postcode) + + # Print the reformatted postcode. + print(postcode) + + # TODO (b) Validate the postcode, returning a match object 'm'. + m = re.search(r"[A-Z]{1,2}\d{2}\s+\d[A-Z]{2}$", postcode) # TODO (b) Replace this line with a call to re.match(). + + if m: + valid = valid + 1 + else: + invalid = invalid + 1 + +print(f"Valid postcodes {valid}") +print(f"Invalid postcodes {invalid}") + +infile.close() + +# TODO (b) Print the valid and invalid totals. + diff --git a/student_exercises/GOT/__init__.py b/student_exercises/GOT/__init__.py new file mode 100644 index 0000000..549b948 --- /dev/null +++ b/student_exercises/GOT/__init__.py @@ -0,0 +1,6 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" diff --git a/student_exercises/GOT/game.py b/student_exercises/GOT/game.py new file mode 100644 index 0000000..63c89d5 --- /dev/null +++ b/student_exercises/GOT/game.py @@ -0,0 +1,58 @@ +#! /usr/bin/env python +# Author: BersuitX +# Description: This about script copy and optionally filter +# source collection to a destination collection using different methods. +""" + Docstring: +""" +from random import random, randint + +import tank +import sys + +def main(): + winner = None + erik_tank = tank.Tank("german", "tiger") + zane_tank = tank.Tank("american", "sherman") + aram_tank = tank.Tank("british", "churchill") + + aram_tank.accel(randint(1, 100)) + erik_tank.accel(randint(1,100)) + zane_tank.accel(randint(1,100)) + + aram_tank.rotate_left(randint(0,360)) + erik_tank.rotate_left(randint(0, 360)) + zane_tank.rotate_left(randint(0, 360)) + + aram_tank.accel(randint(1,100)) + erik_tank.accel(randint(1, 100)) + zane_tank.accel(randint(1, 100)) + + aram_tank.shoot() + erik_tank.shoot() + zane_tank.shoot() + + aram_tank.take_damage(randint(1, 99)) + erik_tank.take_damage(randint(1,99)) + zane_tank.take_damage(randint(1,99)) + + # print(f"Health of Erik-s tanks is {erik_tank._health}") + # print(f"Health of Aram's tanks is {aram_tank._health}") + # print(f"Health of Zane's tanks is {zane_tank._health}") + # print(f"Status of Erik's and Zane's is {erik_tank + zane_tank}") + # # erik_tank.set_health(100 - erik_tank._health) + # print(f"Health of Erik-s tanks is {erik_tank._health}") + print(aram_tank.__dict__) + print(erik_tank.__dict__) + print(zane_tank.__dict__) + + # if erik_tank._health > zane_tank._health > aram_tank._health: + # winner = erik_tank.country + + print(f"And the winner is: {winner}") + + return None + +if __name__ == "__main__": + main() + sys.exit(0) \ No newline at end of file diff --git a/student_exercises/GOT/tank.py b/student_exercises/GOT/tank.py new file mode 100644 index 0000000..7c1f2ee --- /dev/null +++ b/student_exercises/GOT/tank.py @@ -0,0 +1,57 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script copy and optionally filter +# source collection to a destination collection using different methods. +""" + Docstring: +""" +import vehicule + +class Tank(vehicule.Vehicle): + # Attributes/Data + Behaviour/Methods + def __init__(self, country, model): + super().__init__(country, model) + self._location = {'x':0, 'y':0, 'z':0} + self._direction = 0 + self._shells = 20 + self._health = 100 + # No Explicit Return, as called implicitly. + + + def accel(self, increase): + self._speed += increase + return None + + def decel(self, decrease): + self._speed -= decrease + return None + + def rotate_left(self, degrees): + self._direction -= degrees % 360 + return None + + def rotate_right(self, degrees): + self._direction += degrees % 360 + return None + + def shoot(self): + self._shells -= 1 + return None + + def take_damage(self, damage): + self._health -= damage + return None + + def __add__(self, other): + return self._health + other._health + + def __del__(self): + print("Boom..!") + return None + + def get_health(self): + return self._health + + def set_health(self, newhealth): + self._health = newhealth + return None diff --git a/student_exercises/GOT/vehicule.py b/student_exercises/GOT/vehicule.py new file mode 100644 index 0000000..cf2bd04 --- /dev/null +++ b/student_exercises/GOT/vehicule.py @@ -0,0 +1,21 @@ +#! /usr/bin/env python +# Author: BersuitX +# Description: This about script copy and optionally filter +# source collection to a destination collection using different methods. +""" + Vehicle Base Class +""" + +class Vehicle: + def __init__(self, country, model): + self.country = country + self.model = model + self._speed = 0 + + def accel(self, increase): + self._speed += increase + return None + + def decel(self, decrease): + self._speed -= decrease + return None \ No newline at end of file diff --git a/Python3_course_diagrams__Feb_2024.pdf b/student_exercises/Python3_course_diagrams__Feb_2024.pdf similarity index 100% rename from Python3_course_diagrams__Feb_2024.pdf rename to student_exercises/Python3_course_diagrams__Feb_2024.pdf diff --git a/student_exercises/__init__.py b/student_exercises/__init__.py new file mode 100644 index 0000000..549b948 --- /dev/null +++ b/student_exercises/__init__.py @@ -0,0 +1,6 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" diff --git a/student_exercises/calc/__init__.py b/student_exercises/calc/__init__.py new file mode 100644 index 0000000..549b948 --- /dev/null +++ b/student_exercises/calc/__init__.py @@ -0,0 +1,6 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" diff --git a/student_exercises/calc/adv.py b/student_exercises/calc/adv.py new file mode 100644 index 0000000..868927a --- /dev/null +++ b/student_exercises/calc/adv.py @@ -0,0 +1,32 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does advance calculator functions +""" + Docstring: Includes mod, power, and sqrt +""" + +import sys + +def mod(x, z): + """ return Remainder of x divided by z """ + return x % z + +def power(x, z): + """ Return power of x to z """ + return x**z + +def sqrt(x): + """ Return square root of x""" + return round(x**0.5, 2) + +def main(): + print("Advanced Calculator App") + print("-" * 30) + print(f"100 % 30 = {mod(100, 30)}") + print(f"100 ** 3 = {power(100, 3)}") + print(f"\N{square root}100 = {sqrt(100)}") + return None + +if __name__ == "__main__": + main() + sys.exit(0) diff --git a/student_exercises/calc/basic.py b/student_exercises/calc/basic.py new file mode 100644 index 0000000..7a7a3d7 --- /dev/null +++ b/student_exercises/calc/basic.py @@ -0,0 +1,35 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" +import sys + +def add(*args): + total = 0 + for num in args: + total += num + return total + +def mul(*args): + total = 1 + for num in args: + total *= num + return total + +def div(x, y): + return round(x/y, 3) + +def main(): + print("Basic Calculator App") + print(f"4 + 3 = {add(4,3)}") + print(f"4 + 3 + 2 = {add(4,3,2)}") + print(f"4 * 3 = {mul(4, 3)}") + print(f"4 * 3 * 2 = {mul(4,3,2)}") + print(f"4 / 3 = {div(4,3)}") + return None + +if __name__ == "__main__": + main() + sys.exit(0) diff --git a/student_exercises/calc/calc.py b/student_exercises/calc/calc.py new file mode 100644 index 0000000..87a4b4f --- /dev/null +++ b/student_exercises/calc/calc.py @@ -0,0 +1,34 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +import sys +import basic +import adv + +def main(): + menu = """ + Calculator App + -------------- + 1. test basic + 2. test Adv + """ + + print(menu) + option = input("Choose 1 or 2: ") + if option == "1": + print(f"100 + 50 + 25 + 12.5 = {basic.add(100, 50, 25, 12.5)}") + print(f"100 * 50 * 25 * 12.5 = {basic.mul(100, 50, 25, 12.5)}") + elif option == "2": + print(f"Modulus of 100 by 45 = {adv.mod(100, 45)}") + print(f"Square root of 25 = {adv.sqrt(25)}") + else: + print("Invalid options") + return None + +if __name__ == "__main__": + main() + sys.exit(0) \ No newline at end of file diff --git a/student_exercises/demo_advance_collections.py b/student_exercises/demo_advance_collections.py new file mode 100644 index 0000000..7506034 --- /dev/null +++ b/student_exercises/demo_advance_collections.py @@ -0,0 +1,54 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script copy and optionally filter +# source collection to a destination collection using different methods. +""" + Docstring: +""" + +# Source collection - list of string +students = ['euler', 'jorge', 'aram', 'mark', 'elizabeth', 'jeremy', ' erik', 'javonn', + 'kirill', 'euler', 'aram'] + +# Iterate through the collection and copy to a destination +# Using an ITERATOR loop plus source, optional condition and expression +wee_names = [] +for name in students: + if len(name) <= 5: + wee_names.append(name.upper()) + +print(f"1.Short names = {wee_names}") + +# Using an ITERATOR loop plus source, user function for filtering, an expression +def filter_names(name): + if len(name) <= 5: + return True + else: + return False + +wee_names = [] +for name in students: + if filter_names(name): + wee_names.append(name.upper()) + +print(f"2.Short names = {wee_names}") + +# Using built-in functions + +wee_names = list(filter(filter_names, students)) +print(f"3.Short names = {wee_names}") + +wee_names = list(filter(lambda name:len(name) <= 5, students)) +print(f"4.Short names = {wee_names}") + +wee_names = [ name.upper() for name in students if len(name) <=5 ] +print(f"5.Short names = {wee_names}") + +wee_names = [ (name.upper(), len(name)) for name in students if len(name) <=5 ] +print(f"6.Short names = {wee_names}") + +wee_names = { name.upper(): len(name) for name in students if len(name) <=5 } +print(f"6.Short names = {wee_names}") + +wee_names = { name.upper() for name in students if len(name) <=5 } +print(f"8.Short names = {wee_names}") diff --git a/student_exercises/demo_calc.py b/student_exercises/demo_calc.py new file mode 100644 index 0000000..0c8e0e9 --- /dev/null +++ b/student_exercises/demo_calc.py @@ -0,0 +1,23 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Calculator app with add, multiply and divide functions +""" + + +def add(x, z): + return float(x+z) + +def mul(x, z): + return float(x*z) + +def div(x, z): + return round(x/z, 3) + +print(f"4 + 3 = {add(4, 3)}") +print(f"4 + 3 = {mul(4, 3)}") +print(f"4 + 3 = {div(4, 3)}") + +l_add = lambda x, z:float(x+z) +print(f"4 + 3 = {l_add(4, 3)}") \ No newline at end of file diff --git a/student_exercises/demo_collections_generator_functions.py b/student_exercises/demo_collections_generator_functions.py new file mode 100644 index 0000000..7eccdaf --- /dev/null +++ b/student_exercises/demo_collections_generator_functions.py @@ -0,0 +1,17 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" +def get_numbers(): + # numbers = [] + for x in range(0, 100): + # numbers.append(x) + # return numbers + yield x + +for z in get_numbers(): + print(id(z)) + +print(id(get_numbers())) \ No newline at end of file diff --git a/student_exercises/demo_counter_loops.py b/student_exercises/demo_counter_loops.py new file mode 100644 index 0000000..48906a1 --- /dev/null +++ b/student_exercises/demo_counter_loops.py @@ -0,0 +1,25 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script HOWTO repeat a block of +# commands a specific number of times using a COUNTER loop. +""" + Docstring: +""" + +count = 0 # 1.Init counter +while count < 10: # 2.Test counter + print(count) + count += 1 # 4.Increment counter + +# Alternatively, we could use a FOR loop plus the built-in +# range(start, stop, step) function. STEP increment is INTEGER! +for num in range(0, 10, 2): + print(num) + +# range(start, stop, step=1) function. +for num in range(0, 10): + print(num) + +# range(start=0, stop, step=1) function. +for num in range(10): + print(num) \ No newline at end of file diff --git a/student_exercises/demo_dict_movies.py b/student_exercises/demo_dict_movies.py new file mode 100644 index 0000000..ba2b172 --- /dev/null +++ b/student_exercises/demo_dict_movies.py @@ -0,0 +1,53 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script How to create, and grow, and shrink +# dictionaires (Undereoed,Collections with UNIQUE keys) +# NOTE: dict are in INSERTION order after Python 3.6. + +""" + Docstring: +""" +import pprint +movies = { + 'william': ['fury', 'pulp fiction', 'shawshank redemption'], + 'kirill': ['pulp fiction', 'the departed', 'snach'], + 'mark': ['fifth element', 'armageddon', 'slapshot'], + 'mahendran': ['titanic', 'rambo', 'men in black'], +} + +# Grow the dict +movies['elizabeth'] = ['gladiator', 'mulan', 'six triple eight'] +movies['erik'] = ['star wars', 'blue velvet', 'edge of tomorrow'] + +pprint.pprint(movies) +print("-" * 60) + +# Grow the dict +movies['erik'] = ['star wars', 'blue velvet', 'dune'] +movies['elizabeth'] = ['gladiator', 'mulan', 'six triple eight'] + +# Remove key-value pairs from dict +movies.pop('mark') # Remove key + value +movies.popitem() # Remove LAST key+value INSERTED + +pprint.pprint(movies) +print("-" * 60) +print(f"Erik's ultimate film is {movies.get('erik')}") +print(f"Erik's favourite films are {movies['erik']}") # Prefer this over above! +print(f"Erik's ultimate film is {movies['erik'][0]}") + +# films = movies.copy() # Copy dict +# films.clear() # Empty dictionary +# pprint.pprint(films) + +# ITERATE through the dict keys by using the .keys() method +for person in movies.keys(): + print(f"{person} likes {movies[person]}") + +# ITERATE through the dict VALUES by using the .values() method +for films in movies.values(): + print(f"Good films = {films}") + +# ITERATE through the dict KEYS+VALUES by using the .items() method +for (person, films) in movies.items(): + print(f"{person} loves {films}") \ No newline at end of file diff --git a/student_exercises/demo_error.py b/student_exercises/demo_error.py new file mode 100644 index 0000000..eac7c82 --- /dev/null +++ b/student_exercises/demo_error.py @@ -0,0 +1,50 @@ +#! /usr/bin/env python3 +# Author: DCameron +# Description: This script will generate 6 RANDOM lottery numbers. +""" + Docstring: +""" +import re +import sys + +class BillandTed(BaseException): + pass + +# Example of a user function with parameter passing +# and default values +def search_pattern(pattern=r"^.{19}$", file=r"c:\labs\words"): + # assert file != None, "No filename given for search_pattern" + if not file: + raise BillandTed('Excellent') + + lines = 0 + try: + fh_in = open(file, mode="rt") + except PermissionError as err: + print(f"Error code={err.args[0]}, {err.args[1]}, {err.filename}", file=sys.stderr) + sys.exit(1) + except FileNotFoundError as err: + print(f"Error code={err.args[0]}, {err.args[1]}, {err.filename}", file=sys.stderr) + sys.exit(2) + except BaseException as err: + print("Error occurred, investigate", file=sys.stderr) + sys.exit(3) + else: + # Executes if try block succeeds + reobj = re.compile(pattern) # Compile pattern ONCE + for line in fh_in: + m = reobj.search(line) + if m: + lines += 1 + print(f"Matched {m.group()} on {line.rstrip()} at {m.start()} - {m.end()}") + finally: + print("And now for something completely different..") + fh_in.close() + return lines + +def main(): + search_pattern() + return None + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/student_exercises/demo_file_context_resource_manager.py b/student_exercises/demo_file_context_resource_manager.py new file mode 100644 index 0000000..b3296bd --- /dev/null +++ b/student_exercises/demo_file_context_resource_manager.py @@ -0,0 +1,37 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does open, close, and +# read, write and add to a text file +""" + Docstring: +""" + +movies = { + 'william': ['fury', 'pulp fiction', 'shawshank redemption'], + 'kirill': ['pulp fiction', 'the departed', 'snach'], + 'mark': ['fifth element', 'armageddon', 'slapshot'], + 'mahendran': ['titanic', 'rambo', 'men in black'], +} + +with open(r"/student_exercises/movies.txt", mode="wt") as fh_out: + # Iterate + for name in movies.keys(): + print(f"{name} {movies[name]}", end="\n") + #fh_out.write(name + str(movies[name])) + fh_out.write(f"{name} str{movies[name]}\n") + +print("-" * 60) +fh_in = open(r"/student_exercises/movies.txt", mode="rt") + +# text = fh_in.read() # Read entire file into string object +# text = fh_in.read(30) # Read entire file into string object +# text = fh_in.read(30) # Read entire file into string object +# text = fh_in.readline() # Read entire file into string object +# text_lines = fh_in.readlines() # Read entire file into string object + +# print(type(text_lines)) + +for line in fh_in: + print(line, end="") + +fh_in.close() \ No newline at end of file diff --git a/student_exercises/demo_file_random_rw.py b/student_exercises/demo_file_random_rw.py new file mode 100644 index 0000000..57110e7 --- /dev/null +++ b/student_exercises/demo_file_random_rw.py @@ -0,0 +1,34 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" +movies = { 'william': ['fury', 'pulp fiction', 'shawshank redemption'], + 'kirill': ['pulp fiction', 'the departed', 'snatch'], + 'mark': ['fifth element', 'armageddon', 'slapshot'], + 'mahendran': ['titanic', 'rambo', 'men in black'] +} +SOF = 0 # Start of file +CUR = 1 # Current file position +EOF = 2 # End of File + +# Open a file handle for READING in TEXT mode +with open(r"movies.txt", mode="rt") as fh_in: + fh_in.seek(90, SOF) # Seek forwards 90 chars from SOF. + text = fh_in.read(30) + print(f"Text at {fh_in.tell() - len(text)} = {text}") + + fh_in.seek(140, SOF) # Seek forwards 140 chars from SOF + text = fh_in.read(30) + print(f"Text at {fh_in.tell() - len(text)} = {text}") + +# Open a file handle for READING in BINARY mode +with open(r"movies.txt", mode="rb") as fh_in: + fh_in.seek(-90, EOF) # Seek backwards 90 bytes from EOF. + text = fh_in.read(30) + print(f"Bytes at {fh_in.tell() - len(text)} = {text}") + + fh_in.seek(-65, CUR) # Seek back 65 bytes from CURRENT position + text = fh_in.read(140) + print(f"Bytes at {fh_in.tell() - len(text)} = {text}") \ No newline at end of file diff --git a/student_exercises/demo_file_seq_rw.py b/student_exercises/demo_file_seq_rw.py new file mode 100644 index 0000000..027fb64 --- /dev/null +++ b/student_exercises/demo_file_seq_rw.py @@ -0,0 +1,41 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does open, close, and +# read, write and add to a text file +""" + Docstring: +""" + +movies = { + 'william': ['fury', 'pulp fiction', 'shawshank redemption'], + 'kirill': ['pulp fiction', 'the departed', 'snach'], + 'mark': ['fifth element', 'armageddon', 'slapshot'], + 'mahendran': ['titanic', 'rambo', 'men in black'], +} + +fh_out = open(r"/student_exercises/movies.txt", mode="wt") + +# Iterate +for name in movies.keys(): + print(f"{name} {movies[name]}", end="\n") + #fh_out.write(name + str(movies[name])) + fh_out.write(f"{name} str{movies[name]}\n") + + +fh_out.close() + +print("-" * 60) +fh_in = open(r"/student_exercises/movies.txt", mode="rt") + +# text = fh_in.read() # Read entire file into string object +# text = fh_in.read(30) # Read entire file into string object +# text = fh_in.read(30) # Read entire file into string object +# text = fh_in.readline() # Read entire file into string object +# text_lines = fh_in.readlines() # Read entire file into string object + +# print(type(text_lines)) + +for line in fh_in: + print(line, end="") + +fh_in.close() \ No newline at end of file diff --git a/student_exercises/demo_iterator_loop.py b/student_exercises/demo_iterator_loop.py new file mode 100644 index 0000000..a26da8b --- /dev/null +++ b/student_exercises/demo_iterator_loop.py @@ -0,0 +1,32 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script HOWTO ITERATE through a SEQUENCE +# ONE item at a time using an ITERATOR for loop. +""" + Docstring: +""" +# 0 1 2 3 4 +films = ['casshern', 'pulp fiction', 'idiocracy', 'matrix', 'pursuit of happiness', + 'titanic', 'lotr', 'top gun'] + +# ITERATE through my list sequence one film at a time +# Using an ITERATOR for loop. +for film in films: + print(film, end="\n") + +# ITERATE through and MODIFY my list sequence one film at a time +# Using an ITERATOR for loop. +idx = 0 +for film in films: + print(film.upper(), end="\n") + films[idx] = film.upper() + idx += 1 +print(films) + +# ITERATE through and MODIFY my list sequence one film at a time +# Using an ITERATOR for loop and built-in enumerate() function. +# enumerate(seq, start=0) returns TUPLE(idx, object) +for (idx, film) in enumerate(films, start=0): + print(film.title(), end="\n") + films[idx] = film.title() +print(films) \ No newline at end of file diff --git a/student_exercises/demo_joy_of_sets.py b/student_exercises/demo_joy_of_sets.py new file mode 100644 index 0000000..1f6e9e9 --- /dev/null +++ b/student_exercises/demo_joy_of_sets.py @@ -0,0 +1,38 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This script will demo HOWTO create a set, grow a set, shrink +# a set and combine sets using SET OPERATORS (Remember VENN Diagrams) +# SETS are UNORDERED! +""" + Docstring: +""" + +marvel_fans = {'donald', 'erik', 'stephen', 'aram', 'jorge', 'lokesh'} +dc_fans = set() # Create an empty SET! + +# Grow a SET +dc_fans.add('donald') +dc_fans.add('zane') +dc_fans.add('matthew') + +# Shrink a SET +# dc_fans.pop() # Randomly REMOVE an object. + +comic_fans = dc_fans.copy() # Copy SET +comic_fans.clear() # Empty SET + +print(f"Fans of Marvel = {marvel_fans}") +print(f"Fans of DC = {dc_fans}") +print("-" * 60) + +# COMBINE the SETS using SET operations (Remember VENN Diagrams). +print(f"Fans of Marvel OR DC = {marvel_fans.union(dc_fans)}") +print(f"Fans of Marvel AND DC = {marvel_fans.intersection(dc_fans)}") +print(f"Fans of ONLY Marvel = {marvel_fans.difference(dc_fans)}") +print(f"Fans of ONLY Marvel OR DC = {marvel_fans.symmetric_difference(dc_fans)}") +print("-" * 20) +# COMBINE the SETS using SET OPERATORS (Remember VENN Diagrams). +print(f"Fans of Marvel OR DC = {marvel_fans | dc_fans}") +print(f"Fans of Marvel AND DC = {marvel_fans & dc_fans}") +print(f"Fans of ONLY Marvel = {marvel_fans - dc_fans}") +print(f"Fans of ONLY Marvel OR DC = {marvel_fans ^ dc_fans}") \ No newline at end of file diff --git a/student_exercises/demo_objects.py b/student_exercises/demo_objects.py new file mode 100644 index 0000000..91a0704 --- /dev/null +++ b/student_exercises/demo_objects.py @@ -0,0 +1,34 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +s1 = "a" +s2 = "e" +s3 = "i" +s4 = "j" +s5 = "b" + +a = "a", "b", "c" +b = ("d", "e", "f") +c = {"g", "h", "i"} +d = ["j", "k", "l"] +e = {"a":"1", "b":"2"} +f = c.add("1") + +print(type(a)) +print(type(b)) +print(type(c)) +print(type(d)) +print(type(e)) +print(type(f)) + +print(s1 in a) +print(s2 in b) +print(s3 in c) +print(s4 in d) +print(s5 in e) +print(f) + diff --git a/student_exercises/demo_pickle.py b/student_exercises/demo_pickle.py new file mode 100644 index 0000000..7f6a2ef --- /dev/null +++ b/student_exercises/demo_pickle.py @@ -0,0 +1,33 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +import pickle +import pprint +import gzip # Others such tarfile, shutil, bz2 + +movies = { 'william': ['fury', 'pulp fiction', 'shawshank redemption'], + 'kirill': ['pulp fiction', 'the departed', 'snatch'], + 'mark': ['fifth element', 'armageddon', 'slapshot'], + 'mahendran': ['titanic', 'rambo', 'men in black'] +} + +# Open a file handle for WRITING in BINARY mode +# with open(r"c:\users\donal\course\Python_Labs_Feb_2025\movies.p", mode="wb") as fh_out: +with gzip.open(r"movies.pgz", mode="wb") as fh_out: + # pickle.dump(movies, fh_out, protocol=5) # Pickle Protocol (0=ASCII, 1-5=Binary) + # pickle.dump(movies, fh_out, pickle.DEFAULT_PROTOCOL) # Default 5 + pickle.dump(movies, fh_out, pickle.HIGHEST_PROTOCOL) # Highest 5 + + +# Open a file handle for READING in BINARY mode +# with open(r"c:\users\donal\course\Python_Labs_Feb_2025\movies.p", mode="rb") as fh_in: +with gzip.open(r"movies.pgz", mode="rb") as fh_in: + films = pickle.load(fh_in) + +pprint.pprint(movies) +print("-" * 60) +pprint.pprint(films) \ No newline at end of file diff --git a/student_exercises/demo_pin.py b/student_exercises/demo_pin.py new file mode 100644 index 0000000..8cb3bc6 --- /dev/null +++ b/student_exercises/demo_pin.py @@ -0,0 +1,17 @@ +#! /usr/bin/python +# +# +# + +master_pin = "0123" +pin = None + +while master_pin != pin: + pin = input("Enter PIN: ") + if pin == master_pin: + print("Valid PIN") + else: + print("Invalid PIN") + +print("Done.") + diff --git a/student_exercises/demo_platform.py b/student_exercises/demo_platform.py new file mode 100644 index 0000000..07d8240 --- /dev/null +++ b/student_exercises/demo_platform.py @@ -0,0 +1,16 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +import sys +import os + +if sys.platform == "win32": + home_dir = os.environ["HOMEPATH"] +else: + home_dir = os.environ["HOME"] + +print(home_dir) \ No newline at end of file diff --git a/student_exercises/demo_read_file.py b/student_exercises/demo_read_file.py new file mode 100644 index 0000000..5e895f9 --- /dev/null +++ b/student_exercises/demo_read_file.py @@ -0,0 +1,20 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" +for line in open('messier.txt', encoding="latin-1"): + # print(len(line)) + line.replace(" ","|", count=-1) + if line.startswith("M"): + print(line, end="") + + # heroes = ['john doe', 'donald', 'Ada lovelace', 'keanu reeves'] + # print(min(heroes)) + # print(max(heroes)) + # a, b, c, *d = 10, 20, 30, 40, 50, 60 + # print(*d) + # print(dir(heroes)) + # heroes.sort() + # print(type(heroes)) \ No newline at end of file diff --git a/student_exercises/demo_regex.py b/student_exercises/demo_regex.py new file mode 100644 index 0000000..ed3c2ed --- /dev/null +++ b/student_exercises/demo_regex.py @@ -0,0 +1,58 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +import re + +fh_in = open("c:\\labs\\words", mode="rt") + +for line in fh_in: + # if line.startswith("Y") and line.rstrip("\n").endswith("n") and "town" in line: + # m = re.search("^the", line) + # m = re.search("ing$", line) + # m = re.search("^ring$", line) + # m = re.search("^......$", line) + # m = re.search("^.ing$", line) + m = re.search(r"\d{1,3}", line) + if m: + print(line, end="") + + +# Author: DCameron +# Description: This script will generate 6 RANDOM lottery numbers. +""" + Docstring: +""" +import re + +# Open File Handle for READING in TEXT mode +fh_in = open(r"c:\labs\words", mode="rt") + +# ITERATE through file handle one line at a time. +for line in fh_in: + # Example of str testing = GOOD! + # if line.startswith("Y") and line.rstrip("\n").endswith("n") and "town" in line: + # m = re.search(r"^the", line) # Match lines starting with 'the' + # m = re.search(r"ing$", line) # Match lines ending with 'ing' + # m = re.search(r"^ring$", line) # Match lines ending with 'ing' + # m = re.search(r"^.ing$", line) # Match lines of 4 chars ending with 'ing' + # m = re.search(r"^...................$", line) # Match lines of exactly 19 chars + # m = re.search(r"^.{19}$", line) # Match lines of exactly 19 chars + # m = re.search(r"^[adr]ing$", line) # Match lines with [adr] followed 'ing' + # m = re.search(r"^[A-Z]", line) # Match lines starting with a CAPITAL + # m = re.search(r"[aeiou][aeiou][aeiou]", line) # Match lines 3 consecutive vowels + # m = re.search(r"[aeiou]{5,}", line) # Match lines 5 consecutive vowels + # m = re.search(r"[0-9][0-9]", line) # Match lines 2 consecutive digits + # m = re.search(r"\.", line) # Match lines with a DOT. You will be WARNED! + # m = re.search(r"[.]", line) # ANOTHER WAY TO ESCAPE! + # m = re.search(r"^[A-Z].*[A-Z]$", line) # Match lines start/end with a CAPITAL + # m = re.search(r"^[A-Z].{4}[A-Z]$", line) # Match lines of 6 chars start/end with a CAPITAL + # m = re.match(r"^[A-Z].{4}[A-Z]$", line) # AUTO MATCHES LINES STARTING WITH... + # m = re.fullmatch(r"^[A-Z].{4}[A-Z]\n$", line) # Match ENTIRE LINE incl HIDDEN chars! + # m = re.search(r"^(.)(.).\2\1$", line) # Match lines 5 char palindromes + m = re.search(r"^([A-Z]).*\1$", line) # Match lines start/end with SAME CAPITAL! + if m: + print(line, end="") \ No newline at end of file diff --git a/student_exercises/demo_regex_precompile.py b/student_exercises/demo_regex_precompile.py new file mode 100644 index 0000000..a58a1fd --- /dev/null +++ b/student_exercises/demo_regex_precompile.py @@ -0,0 +1,17 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +import re + +fh_in = open(r"c:\\labs\\words", mode="rt") + +reobj = re.compile(r"^([A-Z]).*\1$") + +for line in fh_in: + m = reobj.search(line) # Match lines start/end with SAME CAPITAL! + if m: + print(line, end="") \ No newline at end of file diff --git a/student_exercises/demo_regex_sub.py b/student_exercises/demo_regex_sub.py new file mode 100644 index 0000000..dd2d0dc --- /dev/null +++ b/student_exercises/demo_regex_sub.py @@ -0,0 +1,16 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does HOWto match and subtitute +# a pattern a replacement string +""" + Docstring: +""" + +# Sample line from /etc/passwd on linux for the root user login + +import re + +line = "root:x:0:0:The Super User:/root:/bin/ksh" +line = re.sub(r"[Ss]uper [Uu]ser", r"Administrator", line) +(line, num) = re.subn(r"ksh", r"bash", line) +print(f"Modified line = {line} with {num} changes") diff --git a/student_exercises/demo_shelve.py b/student_exercises/demo_shelve.py new file mode 100644 index 0000000..ec0a809 --- /dev/null +++ b/student_exercises/demo_shelve.py @@ -0,0 +1,34 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +import shelve + +movies = { + 'william': ['fury', 'pulp fiction', 'shawshank redemption'], + 'kirill': ['pulp fiction', 'the departed', 'snach'], + 'mark': ['fifth element', 'armageddon', 'slapshot'], + 'mahendran': ['titanic', 'rambo', 'men in black'], +} +tv_series = { 'william': ['fame', 'walking dead'], + 'kirill': ['got', 'outlander'], + 'mark': ['cagney and lacey', 'scooby doo'] +} + +books = { 'william': 'the hobbit', + 'kirill': 'lotr', + 'mark': 'world war z' +} + +with shelve.open(r"movies") as db: + db['movies'] = movies + db['tv_series'] = tv_series + db['books'] = books + +with shelve.open(r"movies") as db: + print(f"Williams favourite movies are {db['movies']['william']}") + print(f"Kirill's favourite tv_Series is {db['tv_series']['kirill'][0]}") + print(f"Mark's favourite book is {db['books']['mark']}") \ No newline at end of file diff --git a/student_exercises/demo_str_formatting.py b/student_exercises/demo_str_formatting.py new file mode 100644 index 0000000..9c9bf9c --- /dev/null +++ b/student_exercises/demo_str_formatting.py @@ -0,0 +1,25 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +planets = {"Mercury":"58.1", "Venus":"60.1", "Earth":"32.1", "Mars":"22.1"} +for planet in planets.keys(): + print("\t\t" + planet + ": " + str(planets[planet]) + " Gm\t" + str(hex(0xff))) + +print("-" * 60) +# Use str concat plus justify methods - OK! +for planets in planets.keys(): + print(planet.rjust(12) + ": " + str(planets[planet].center(12, '.') + " Gm " + str(hex(0xff)))) + +print("-" * 60) +# Use str.format() method - GOOD! plus justify methods - OK! +for planets in planets.keys(): + print() + +print("-" * 60) +# Use str.format() method - GOOD! plus justify methods - OK! +for planets in planets.keys(): + print() diff --git a/student_exercises/demo_str_split_join.py b/student_exercises/demo_str_split_join.py new file mode 100644 index 0000000..db80984 --- /dev/null +++ b/student_exercises/demo_str_split_join.py @@ -0,0 +1,18 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +# Sample /etc/passwd on Linux +line = "root:x:0:0:The super User:/root:/bin/ksh" + +# Separeted the line in fields according char +fields = line.split(":") +fields[4] = "The Administrator" +fields[6] = "/bin/bash" + +line = ":".join(fields) + +print(line) \ No newline at end of file diff --git a/student_exercises/demo_unicode_table.py b/student_exercises/demo_unicode_table.py new file mode 100644 index 0000000..0ba514b --- /dev/null +++ b/student_exercises/demo_unicode_table.py @@ -0,0 +1,23 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" +#! /usr/bin/env python3 +# Author: DCameron +# Description: This script will demo HOWTO display the ENTIRE +# UNICODE char set +""" + Docstring: +""" + +# ITERATE through all the chars in the Unicode table +# using an ITERATOR for loop (0->65535) +for pos in range(0, 65536): + try: + print(chr(pos), end=" ") + if pos % 16 == 0: + print() + except UnicodeError: + print(" ", end=" ") \ No newline at end of file diff --git a/student_exercises/demo_unused_services.py b/student_exercises/demo_unused_services.py new file mode 100644 index 0000000..2f355fa --- /dev/null +++ b/student_exercises/demo_unused_services.py @@ -0,0 +1,20 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + +import sys +import re + +with open(r"c:\\Windows\\System32\drivers\etc\services", mode="rt") as service: + for line in service: + if line.isspace(): continue + obj = re.compile("^#") + if not obj.search(line): + line = re.sub(r"\s+", repl="#", string=line) + s = line.split("#") + pp = s[1].split("/") + if int(pp[0]) <= 200: + print(f"Service: {s[0]} Port: {s[1]}", end="\n") diff --git a/student_exercises/demo_user_function.py b/student_exercises/demo_user_function.py new file mode 100644 index 0000000..0744a99 --- /dev/null +++ b/student_exercises/demo_user_function.py @@ -0,0 +1,20 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script describe the use of functions +""" + Docstring: +""" + +def say_hello(greeting:str="Hi", recipient:str="friends", *countries): + message = str(greeting) + " " + str(recipient) + print(message) + return None + +say_hello("Hola", "Amigos") +say_hello(greeting="Hi", recipient="guys!") +say_hello(greeting="Hi", recipient="guys!") +say_hello("yo", recipient="homies!") +say_hello("bonjour", 5) +say_hello(greeting="yaya", recipient="Locos") +say_hello() + diff --git a/student_exercises/demo_zipping.py b/student_exercises/demo_zipping.py new file mode 100644 index 0000000..e0003db --- /dev/null +++ b/student_exercises/demo_zipping.py @@ -0,0 +1,21 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does HOWTO ITERATE through multiple +# separate but index-related sequences (str/list/tuple/dict/sets) +""" + Docstring: +""" +import sys + +# Create multiple SEPARATE but INDEX-related LISTS. +students = ['erik', 'roberto', 'lokesh'] +fav_heroes = ['ghandi', 'sean connery', 'john travolta'] +fav_bands = ['rolling stones', 'beatles', 'ac/dc'] +fav_locations = ['bassano del grappa', 'venice', 'switzerland'] + +# ITERATE through the SEPARATE but INDEX-RELATED lists and link indice values +# together using an ITERATOR for loop plus built-in zip() function. +for (s, fh, fb, fl) in zip(students, fav_heroes, fav_bands, fav_locations): + print(s + " likes to listen to " + fb + " with " + fh + " in " + fl) + +sys.exit(0) # Exit script with error code (0=success, 1-255=error code) \ No newline at end of file diff --git a/student_exercises/ex9_gen.py b/student_exercises/ex9_gen.py new file mode 100644 index 0000000..9de90e9 --- /dev/null +++ b/student_exercises/ex9_gen.py @@ -0,0 +1,30 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This about script does +""" + Docstring: +""" + + +def frange(start:float=0.0, end:float=0.0, step:float=0.25): + num_range = [] + while (start <= end) & (step > 0): + num_range.append(start) + start = round(float(start+step),2) + return num_range + + +# num = lambda start, step, end:float(start+step <= end) +# print(num) + +# print(list(frange(end=100, step=7))) +# print(list(frange(5,20))) + +one = list(frange(0, 3.5, 0.25)) +two = list(frange(3.5)) +if one == two: + print("Defaults worked!") +else: + print("Ooops! Defaults did not work") + print("one:", one) + print("two:", two) \ No newline at end of file diff --git a/student_exercises/first.py b/student_exercises/first.py new file mode 100644 index 0000000..ab3a614 --- /dev/null +++ b/student_exercises/first.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python +# Author: BersuitX +# Version: 1.0 +# Description: This is oir first script + +name = input("Enter your name: ") +number = input("Enter the number : ") + +print("My name is", name) +print("My name is " + name) +print("The number is: ", type(number)) + +import random +print("Lucky number is", random.randint(1, 50)) + +from math import cos +print("Cosine of 0.5 is", cos(0.5)) + +import monday +greeting = "Hi " + name +print(greeting) +print(monday._greeting) +print(monday.__greeting) +print(monday.__greeting__) diff --git a/student_exercises/first_file b/student_exercises/first_file new file mode 100644 index 0000000..e69de29 diff --git a/student_exercises/lotto.py b/student_exercises/lotto.py new file mode 100644 index 0000000..83d645c --- /dev/null +++ b/student_exercises/lotto.py @@ -0,0 +1,39 @@ +#! /usr/bin/python +# Author: BersuitX +# Description: This script does +""" + Docstring: +""" + +import random +from asyncio import timeout +from time import sleep + +lotto = set() +dups = set() +historyNumbers = [] +cnt = 0 + +while cnt < 10: + while len(lotto) < 6: + num = random.randint(1, 50) + if num not in historyNumbers and num not in lotto: + lotto.add(num) + else: + print("Duplicate number: ", num) + dups.add(num) + print("Lottery numbers =", lotto, cnt) + historyNumbers.append(lotto) + lotto = set() + cnt += 1 + # sleep(.0009) + +print("Numbers", historyNumbers) +print(f"Duplicates: {dups}") + +# lotto = set() # Empty set +# while len(lotto) < 6: +# num = random.randint(1, 50) +# lotto.add(num) +# +# print("Lottery numbers =", sorted(lotto)) \ No newline at end of file diff --git a/student_exercises/messier.txt b/student_exercises/messier.txt new file mode 100644 index 0000000..4709fb8 --- /dev/null +++ b/student_exercises/messier.txt @@ -0,0 +1,114 @@ +0 1 2 3 4 5 6 7 8 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +M1 The Crab Nebula Supernova remnant Taurus +M2 Globular cluster Aquarius +M3 Globular cluster Canes Venatici +M4 Globular cluster Scorpius +M5 Globular cluster Serpens Caput +M6 Butterfly Cluster Open cluster Scorpius +M7 Ptolemy Cluster Open cluster Scorpius +M8 The Lagoon Nebula Starforming nebula Sagittarius +M9 Globular cluster Ophiuchus +M10 Globular cluster Ophiuchus +M11 Wild Duck Cluster Open cluster Scutum +M12 Globular cluster Ophiuchus +M13 Hercules Great Globular Cluster Globular cluster Hercules +M14 Globular cluster Ophiuchus +M15 C�mulo de Pegaso Globular cluster Pegasus +M16 Eagle Nebula Starforming nebula Serpens Cauda +M17 Swan Nebula Starforming nebula Sagittarius +M18 Open cluster Sagittarius +M19 Globular cluster Ophiuchus +M20 Trifid Nebula Starforming nebula Sagittarius +M21 Open cluster Sagittarius +M22 Sagittarius Cluster Globular cluster Sagittarius +M23 Open cluster Sagittarius +M24 Sagittarius Star Cloud Milky Way star cloud Sagittarius +M25 Open cluster Sagittarius +M26 Open cluster Scutum +M27 Dumbbell Nebula Planetary nebula Vulpecula +M28 Globular cluster Sagittarius +M29 Open cluster Cygnus +M30 Globular cluster Capricornus +M31 Andromeda Galaxy Spiral galaxy Andromeda +M32 Elliptical galaxy Andromeda +M33 Triangulum Galaxy Spiral galaxy Triangulum +M34 Open cluster Perseus +M35 Open cluster Gemini +M36 Open cluster Auriga +M37 Open cluster Auriga +M38 Open cluster Auriga +M39 Open cluster Cygnus +M40 Winnecke 4 Double star Ursa Major +M41 Open cluster Canis Major +M42 Great Orion Nebula Starforming nebula Orion +M43 De Mairan's Nebula Starforming nebula Orion +M44 Beehive Cluster Open cluster Cancer +M45 Pleiades Open cluster Taurus +M46 Open cluster Puppis +M47 Open cluster Puppis +M48 Open cluster Hydra +M49 Elliptical galaxy Virgo +M50 Open cluster Monoceros +M51 Whirlpool Galaxy Spiral galaxy Canes Venatici +M52 Open cluster Cassiopeia +M53 Globular cluster Coma Berenices +M54 Globular cluster Sagittarius +M55 Globular cluster Sagittarius +M56 Globular cluster Lyra +M57 Ring Nebula Planetary nebula Lyra +M58 Spiral galaxy Virgo +M59 Elliptical galaxy Virgo +M60 Elliptical galaxy Virgo +M61 Spiral galaxy Virgo +M62 Globular cluster Ophiuchus +M63 Sunflower Galaxy Spiral galaxy Canes Venatici +M64 Black Eye Galaxy Spiral galaxy Coma Berenices +M65 Spiral galaxy Leo +M66 Spiral galaxy Leo +M67 Open cluster Cancer +M68 Globular cluster Hydra +M69 Globular cluster Sagittarius +M70 Globular cluster Sagittarius +M71 Globular cluster Sagittarius +M72 Globular cluster Aquarius +M73 Open cluster Aquarius +M74 Spiral galaxy Pisces +M75 Globular cluster Sagittarius +M76 Little Dumbell Nebula Planetary nebula Perseus +M77 Spiral galaxy Cetus +M78 Diffuse nebula Orion +M79 Globular cluster Lepus +M80 Globular cluster Scorpius +M81 Bode's Galaxy Spiral galaxy Ursa Major +M82 Cigar Galaxy Irregular galaxy Ursa Major +M83 Southern Pinwheel Galaxy Spiral galaxy Hydra +M84 Lenticular galaxy Virgo +M85 Lenticular galaxy Coma Berenices +M86 Lenticular galaxy Virgo +M87 Virgo A Elliptical galaxy Virgo +M88 Spiral galaxy Coma Berenices +M89 Elliptical galaxy Virgo +M90 Spiral galaxy Virgo +M91 Spiral galaxy Coma Berenices +M92 Globular cluster Hercules +M93 Open cluster Puppis +M94 Spiral galaxy Canes Venatici +M95 Spiral galaxy Leo +M96 Spiral galaxy Leo +M97 Owl Nebula Planetary nebula Ursa Major +M98 Spiral galaxy Coma Berenices +M99 Spiral galaxy Coma Berenices +M100 Spiral galaxy Coma Berenices +M101 Pinwheel Galaxy Spiral galaxy Ursa Major +M102 Spindle Galaxy (maybe) Lenticular galaxy Ursa Major +M103 Open cluster Cassiopeia +M104 Sombrero Galaxy Spiral galaxy Virgo +M105 Elliptical galaxy Leo +M106 Spiral galaxy Canes Venatici +M107 Globular cluster Ophiuchus +M108 Spiral galaxy Ursa Major +M109 Spiral galaxy Ursa Major +M110 Elliptical galaxy Andromeda + +-------------------------------------------------------------------------------- diff --git a/student_exercises/monday.py b/student_exercises/monday.py new file mode 100644 index 0000000..e287a5e --- /dev/null +++ b/student_exercises/monday.py @@ -0,0 +1,6 @@ +#! /usr/bin/python + +_greeting = "Hello world!" +__greeting = "Say bye" +__greeting__ = "Good bye" + diff --git a/student_exercises/movies b/student_exercises/movies new file mode 100644 index 0000000..9ce0bed Binary files /dev/null and b/student_exercises/movies differ diff --git a/student_exercises/movies.pgz b/student_exercises/movies.pgz new file mode 100644 index 0000000..421dedd Binary files /dev/null and b/student_exercises/movies.pgz differ diff --git a/student_exercises/movies.txt b/student_exercises/movies.txt new file mode 100644 index 0000000..a72a742 --- /dev/null +++ b/student_exercises/movies.txt @@ -0,0 +1,4 @@ +william str['fury', 'pulp fiction', 'shawshank redemption'] +kirill str['pulp fiction', 'the departed', 'snach'] +mark str['fifth element', 'armageddon', 'slapshot'] +mahendran str['titanic', 'rambo', 'men in black'] diff --git a/student_exercises/postcodes.txt b/student_exercises/postcodes.txt new file mode 100644 index 0000000..6d86a80 --- /dev/null +++ b/student_exercises/postcodes.txt @@ -0,0 +1,34 @@ +pl71na +bs71ap +N71ja + Bn 2 2bs + ec1v2yy + LS2 99py + YO16 7SH + +gl7 2ef +g17 2ef + gl7 2ef + gl7 2ef +gl7 ef2 + + BN32ff +g1 3er +g1 3er +some text ex20 1uy +gl7 6gh more text +abc 5ex + nr1 4er + cf3 1qw + cf3 1qw + ec3p 3ah +TQ10 4TH +PH339te + +ll33 4yu + 4er nr1 + ox1 3hq + ox1 3hq + +ox35fg + P o155tT diff --git a/student_exercises/sep.py b/student_exercises/sep.py new file mode 100644 index 0000000..2e6b89c --- /dev/null +++ b/student_exercises/sep.py @@ -0,0 +1,13 @@ +#! /usr/bin/python +# 1 2 3 4 +# 012345678901234567890123456789012345678901234567890 +Belgium = 'Belgium,10445852,Brussels,737966,Europe,1830,Euro,Catholicism,Dutch,French,German' + +print("-" * len(Belgium)) +print(Belgium.replace(",", ":")) + +pop_country = int(Belgium[8:16]) # Remember to CONVERT str into int! +pop_capital = int(Belgium[26:32]) + +print(f"Population of Country and capital = {pop_country + pop_capital}") +print("-" * len(Belgium)) \ No newline at end of file