From d180407ae4c78f0ea66cc32448032ab1fc258f30 Mon Sep 17 00:00:00 2001 From: rizaayson Date: Wed, 25 Jun 2025 13:50:29 +0800 Subject: [PATCH] added student repo --- .../__pycache__/activity.cpython-312.pyc | Bin 0 -> 12669 bytes S05/activity/activity.py | 325 ++++++++++++++++ s01/activity/activity.py | 31 ++ s01/discussion/discussion.py | 150 ++++++++ s02/activity/activity.py | 34 ++ s02/discussion/discussion.py | 185 ++++++++++ .../__pycache__/activity.cpython-312.pyc | Bin 0 -> 1542 bytes s03/activity/activity.py | 38 ++ s03/discussion/discussion.py | 337 +++++++++++++++++ .../__pycache__/activity.cpython-312.pyc | Bin 0 -> 4472 bytes s04/activity/activity.py | 109 ++++++ s04/discussion/discussion.py | 349 ++++++++++++++++++ 12 files changed, 1558 insertions(+) create mode 100644 S05/activity/__pycache__/activity.cpython-312.pyc create mode 100644 S05/activity/activity.py create mode 100644 s01/activity/activity.py create mode 100644 s01/discussion/discussion.py create mode 100644 s02/activity/activity.py create mode 100644 s02/discussion/discussion.py create mode 100644 s03/activity/__pycache__/activity.cpython-312.pyc create mode 100644 s03/activity/activity.py create mode 100644 s03/discussion/discussion.py create mode 100644 s04/activity/__pycache__/activity.cpython-312.pyc create mode 100644 s04/activity/activity.py create mode 100644 s04/discussion/discussion.py diff --git a/S05/activity/__pycache__/activity.cpython-312.pyc b/S05/activity/__pycache__/activity.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1d5e572a85beefd2a5070587ddbc873a518c9efc GIT binary patch literal 12669 zcmc&)eQXrR6`wud-R_<5!)F_R+nm1$hru?V36!P@5RybYl!X1fXb8{Qa~S5GWFT|vkN!V{j!kP#-% zjJV=1hPcSXgm;}Le1*VV1`E966;$g6tw*RZwQj2Qf|j*uJygqq)@Rdtsn!qL%F8aj zRMtfVHy_}Ge25QUcI#S>YODANUv1O+sJ4c$%q3crmY06mv7{o_-0!P z0nmE*7QU5lv)Kkg%kry*ARjgB6{5O!f#W+&U0C3T+cku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f~Q7Lm@j9b_dPVJj*s0*jA-|`xSP(LbfaHcB-$RW$O!U zqtd$b3cFJwI~8{4XT�YGz5z`A0t{ZS&5%NYh+o&1_^%A+q)wVVKUzM?Z1Cw#%mh0dIOA_@SJ?i~i2F?VmGF7)W77Bu@l5h_ R-uhW@eZkv!m1v*9{SVv;j;sIx literal 0 HcmV?d00001 diff --git a/S05/activity/activity.py b/S05/activity/activity.py new file mode 100644 index 0000000..b3397f0 --- /dev/null +++ b/S05/activity/activity.py @@ -0,0 +1,325 @@ +## Capstone Specifications + +# 1. In the s05 folder, create an "activity" folder, and inside it, create an "activity.py" file. +# 2. Create a **Person** class, which is an **abstract class**, and includes the following methods: +# - getFullName() method +# - addRequest() method +# - checkRequest() method +# - addUser() method + +from abc import ABC, abstractmethod + +class Person(ABC): + @abstractmethod + def getFullName(self): + pass + + @abstractmethod + def addRequest(self): + pass + + @abstractmethod + def checkRequest(self): + pass + + @abstractmethod + def addUser(self): + pass + +# 3. Create an **Employee** class that **inherits from Person** class, with the following properties and methods: +# - Properties (Define the properties as **protected**, and implement **getters and setters** for each.) +# - firstName +# - lastName +# - email +# - department + +class Employee(Person): + def __init__(firstName, lastName, email, department): + super().__init__() + self._firstName = firstName + self._lastName = lastName + self._email = email + self._department = department + + # getters and setters + def get_firstName(self): + return self._firstName + + def get_lastName(self): + return self._lastName + + def get_email(self): + return self._email + + def get_department(self): + return self._department + + def set_firstName(self, firstName): + self._firstName = firstName + + def set_lastName(self, lastName): + self._lastName = lastName + + def set_email(self, email): + self._email = email + + def set_department(self, department): + self._department = department + +# - Abstract methods +# - getFullName() - outputs the full name +# - addRequest() - outputs "Request has been added" +# - checkRequest() - pass +# - addUser() - pass + + def getFullName(self): + return f"{self._firstName } {self._lastName}" + + def addRequest(self): + return "Request has been added" + + def checkRequest(self): + pass + + def addUser(self): + pass + +# - Custom methods +# - login() - outputs " has logged in" +# - logout() - outputs " has logged out" + + def login(self): + return f"{self._email} has logged in" + + def logout(self): + return f"{self._email} has logged out" + +# 4. Create a **TeamLead** class that **inherits from Person** class with the following properties and methods: +# - Properties (Define the properties as **protected**, and implement **getters and setters** for each.) +# - firstName +# - lastName +# - email +# - department +# - members - empty list + +class TeamLead(Person): + def __init__(self, firstName, lastName, email, department): + super().__init__() + self._firstName = firstName + self._lastName = lastName + self._email = email + self._department = department + self._members = [] + + # getters and setters + def get_firstName(self): + return self._firstName + + def get_lastName(self): + return self._lastName + + def get_email(self): + return self._email + + def get_department(self): + return self._department + + def get_members(self): + return self._members + + def set_firstName(self, firstName): + self._firstName = firstName + + def set_lastName(self, lastName): + self._lastName = lastName + + def set_email(self, email): + self._email = email + + def set_department(self, department): + self._department = department + +# - Abstract methods +# - getFullName() - outputs the full name +# - addRequest() - pass +# - checkRequest() - outputs "Request has been checked" +# - addUser() - pass + + def getFullName(self): + return f"{self._firstName } {self._lastName}" + + def addRequest(self): + pass + + def checkRequest(self): + return "Request has been checked" + + def addUser(self): + pass + +# - Custom methods +# - login() - outputs " has logged in" +# - logout() - outputs " has logged out" +# - addMember() - adds an employee to the members list + + def login(self): + return f"{self._email} has logged in" + + def logout(self): + return f"{self._email} has logged out" + + def addMember(self, teamMember): + self._members.append(teamMember) + +# 5. Create an **Admin** class the **inherits from Person** class with the following properties and methods: +# - Properties (Define the properties as **protected**, and implement **getters and setters** for each.) +# - firstName +# - lastName +# - email +# - department + +class Admin(Person): + def __init__(self, firstName, lastName, email, department): + super().__init__() + self._firstName = firstName + self._lastName = lastName + self._email = email + self._department = department + + # getters and setters + def get_firstName(self): + return self._firstName + + def get_lastName(self): + return self._lastName + + def get_email(self): + return self._email + + def get_department(self): + return self._department + + def set_firstName(self, firstName): + self._firstName = firstName + + def set_lastName(self, lastName): + self._lastName = lastName + + def set_email(self, email): + self._email = email + + def set_department(self, department): + self._department = department + +# - Abstract methods +# - getFullName() - outputs the full name +# - addRequest() - pass +# - checkRequest() - pass +# - addUser() - outputs "User has been added" + + def getFullName(self): + return f"{self._firstName } {self._lastName}" + + def addRequest(self): + pass + + def checkRequest(self): + pass + + def addUser(self): + return "User has been added" + +# - Custom methods +# - login() - outputs " has logged in" +# - logout() - outputs " has logged out" + + def login(self): + return f"{self._email} has logged in" + + def logout(self): + return f"{self._email} has logged out" + +# 6. Create a **Request** class with the following properties and methods: +# - Properties (Define the properties as **protected**, and implement **getters and setters** for each.) +# - name +# - requester +# - dateRequested +# - status - "Open" + +class Request(): + def __init__(self, name, requester, dateRequested): + self._name = name + self._requester = requester + self._dateRequested = dateRequested + self._status = "Open" + + # getters and setters + def get_name(self): + return self._name + + def get_requester(self): + return self._requester + + def get_dateRequested(self): + return self._dateRequested + + def get_status(self): + return self._status + + def set_name(self, name): + self._name = name + + def set_requester(self, requester): + self._requester = requester + + def set_dateRequested(self, dateRequested): + self._dateRequested = dateRequested + + def set_status(self, status): + self._status = status + +# - Custom Methods +# - updateRequest() - outputs “Request has been updated” +# - closeRequest() - outputs “Request has been closed” +# - cancelRequest() - outputs “Request has been cancelled” + + def updateRequest(self): + return f"Request {self._name} has been updated" + + def closeRequest(self): + return f"Request {self._name} has been closed" + + def cancelRequest(self): + return f"Request {self._name} has been cancelled" + +# 7. Comment out the test cases before updating the local session Git repository. +# 8. Update your local session Git repository and push to Git with the commit message "Add activity code s05". +# 9. Add the repository link in Boodle for s05. + +# Test cases: + +employee1 = Employee("John", "Doe", "djohn@mail.com", "Marketing") +employee2 = Employee("Jane", "Smith", "sjane@mail.com", "Marketing") +employee3 = Employee("Robert", "Patterson", "probert@mail.com", "Sales") +employee4 = Employee("Brandon", "Smith", "sbrandon@mail.com", "Sales") +admin1 = Admin("Monika", "Justin", "jmonika@mail.com", "Marketing") +teamLead1 = TeamLead("Michael", "Specter", "smichael@mail.com", "Sales") +req1 = Request("New hire orientation", teamLead1, "27-Jul-2021") +req2 = Request("Laptop repair", employee1, "1-Jul-2021") + +assert employee1.getFullName() == "John Doe", "Full name should be John Doe" +assert admin1.getFullName() == "Monika Justin", "Full name should be Monika Justin" +assert teamLead1.getFullName() == "Michael Specter", "Full name should be Michael Specter" +assert employee2.login() == "sjane@mail.com has logged in" +assert employee2.addRequest() == "Request has been added" +assert employee2.logout() == "sjane@mail.com has logged out" + +teamLead1.addMember(employee3) +teamLead1.addMember(employee4) +for indiv_emp in teamLead1.get_members(): + print(indiv_emp.getFullName()) + +assert admin1.addUser() == "User has been added" + +req2.set_status("closed") +print(req2.closeRequest()) \ No newline at end of file diff --git a/s01/activity/activity.py b/s01/activity/activity.py new file mode 100644 index 0000000..b2d239d --- /dev/null +++ b/s01/activity/activity.py @@ -0,0 +1,31 @@ +# Activity Solution: + +# 1. In the s01 folder, create an "activity" folder, and inside it, create an "activity.py" file. +# 2. Create 5 variables and display them in the terminal using the following format: +# "I am ``, and I am `` years old, I work as a ``, and my rating for `` is ``%." + +name = "Jose" +age = 38 +occupation = "writer" +movie = "One more chance" +rating = 99.6 + + print(f"I am {name}, and I am {age} years old, I work as a {occupation}, and my rating for {movie} is {rating}%.") + +# 3. Create 3 variables named num1, num2, and num3. +num1 = 10 +num2 = 15 +num3 = 12 + +# Print the product of num1 and num2. +print(num1 * num2) + +# Print whether num1 is less than num3. +print(num1 < num3) + +# Add the value of num3 to num2, then print the updated value of num2. +num2 += num3 +print(num2) + +# 4. Update your local session Git repository and push to Git with the commit message "Add activity code s01". +# 5. Add the repository link in Boodle for s01. \ No newline at end of file diff --git a/s01/discussion/discussion.py b/s01/discussion/discussion.py new file mode 100644 index 0000000..4f00e2c --- /dev/null +++ b/s01/discussion/discussion.py @@ -0,0 +1,150 @@ +# [SECTION] Comments in Python + +# In Python, comments are written using the "#" symbol. +# Remember that comments are not read by the program; they are only for the user. +# Comments can also be written inline. + +# [SECTION] Python Syntax + +# print() is a built-in function that displays text or other data in the terminal. +print("Hello world!") +# Result: Hello World! + +# Like JavaScript, Python does not require semicolons at the end of statements. + +# To run a Python program: + + # Windows and Linux + # python discussion.py + + # MacOS + # python3 discussion.py + + # print("Hello World!") + # Result: IndentationError: unexpected indent + +# In many other programming languages, indentation is used only for readability, but in Python, it is essential because it indicates a block of code. + +# [SECTION] Naming convention +# The terminology used for variable names is "identifier." +# All identifiers should begin with a letter (A–Z or a–z) or an underscore (_). +# After the first character, identifiers can have any combination of characters. +# Unlike JavaScript, which uses camelCase, Python follows the snake_case convention for variable names, as defined in PEP 8 (Python Enhancement Proposal 8). +# Keywords cannot be used as identifiers. +# Most importantly, identifiers are case-sensitive. + +age = 20 +middle_initial = "C" + +# [SECTION] Data Types +# Data types convey what kind of information a variable holds. There are different types, each with its own purpose. + +# In Python, these are the commonly used data types: + +# Strings (str) - for alphanumeric characters and symbols +full_name = "John Doe" +secret_code = "Pa$$w0rd" + +# Numbers (int, float, complex) - for integers, decimals, and complex numbers +num_of_days = 365 +pi_approx = 3.1416 +complex_num = 1 + 5j # This is a complex number, j represents the imaginary component + +# Boolean (bool) - for truth values +is_learning = True +is_difficult = False + +# [SECTION] Using variables + +# After declaring variables, they can be used by calling the identifier. +print(full_name) +# Result: John Doe + +# Python allows assigning values to multiple variables in a single line: + +name1, name2, name3, name4 = "John", "Paul", "George", "Ringo" +print(name1) +# Result: John +print(name2) +# Result: Paul +print(name3) +# Result: George +print(name4) +# Result: Ringo + +# In Python, the "+" symbol can be used to concatenate strings. + +print("Concatenation in Python:") + +print("My name is " + full_name) +# Result: My name is John Doe + +# print("My age is " + age) +# Result: TypeError: can only concatenate str (not "int") to str + +# [SECTION] Typecasting in Python + +# There may be times when you want to specify a type for a variable. This can be done using casting. Here are some functions you can use: + +print("Typecasting in Python:") + +# str() - converts the value into string +print("My age is " + str(age)) +# Result: My age is 20 + +# float() - converts the value into float +print(float(age)) +# Result: 20.0 + +# int() - converts the value into integer +print(int(pi_approx)) +# Result: 3 + +# Another way to avoid the type error without using typecasting is by using an f-string. +# To use an f-string, add a lowercase f before the string, and place the variable you want to display inside curly braces {}. +print(f"Hi, my name is {full_name}, and I am {age} years old.") +# Result: Hi, my name is John Doe, and I am 20 years old. + +# [SECTION] Operations + +# Python has families of operators that can be used to manipulate variables. + +# Arithmetic operators - performs mathematical operations +print("Arithmetic Operators:") +print(1 + 10) +# Result: 11 +print(15 - 8) +# Result: 7 +print(18 * 9) +# Result: 162 +print(21 / 7) +# Result: 3.0 +print(18 % 4) +# Result: 2 +print(2 ** 6) +# Result: 64 + +# Assignment Operators - used to assign or update variable values +print("Assignment Operators:") +num1 = 3 +num1 += 4 +print(num1) +# Result: 7 + +# Note: Other assignment operators include -=, *=, /=, %= + +# Comparison Operators - used to compare values (returns a boolean value) +print("Comparison Operators:") +print(1 == 1) +# Result: True + +# Note: Other comparison operators include !=, >=, <=, >, < + +# Logical Operators - used to combine or evaluate multiple conditions +print("Logical Operators:") +print(True and False) +# Result: False +print(not False) +# Result: True +print(False or True) +# Result: True \ No newline at end of file diff --git a/s02/activity/activity.py b/s02/activity/activity.py new file mode 100644 index 0000000..1bc77f1 --- /dev/null +++ b/s02/activity/activity.py @@ -0,0 +1,34 @@ +# Activity Solution: + +# 1. In the s02 folder, create an "activity" folder, and inside it, create an "activity.py" file. +# 2. Accept a "year" input from the user and determine whether it is a leap year or not. + +year = int(input("Please input a year:\n")) +if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: + print(f"{year} is a leap year.") +else: + print(f"{year} is not a leap year." + + +# 3. Accept two numbers ("row" and "column") from the user and create a grid of asterisks based on those values. + +row = int(input("Enter number of rows:\n")) +col = int(input("Enter number of columns:\n")) + +i = 1 +j = 1 +str = "" +while i <= row: + while j <= col: + str += "*" + j += 1 + print(str) + i += 1 + +# 4. Update your local session Git repository and push to Git with the commit message "Add activity code s02". +# 5. Add the repository link in Boodle for s02. + +# Stretch Goal: +# 1. Add a validation for the leap year input: +# - Strings are not allowed for inputs +# - No zero or negative values \ No newline at end of file diff --git a/s02/discussion/discussion.py b/s02/discussion/discussion.py new file mode 100644 index 0000000..fb29e1f --- /dev/null +++ b/s02/discussion/discussion.py @@ -0,0 +1,185 @@ +# [SECTION] User Input + +# Python allows input from the user. + +# The input() function lets the user provide input to the program. +username = input("Please enter your name:\n") + +print(f"Hello {username}! Welcome to the Python short course!") +# Result: Hello John! Welcome to the Python short course! + +num1 = input("Enter 1st number:\n") +num2 = input("Enter 2nd number:\n") + +print(f"The sum of num1 and num2 is {num1 + num2}") +# Result: The sum of num1 and num2 is 1015 + +# To solve this, the input values can be typecast to the appropriate data type. +num1 = int(input("Enter 1st number:\n")) +num2 = int(input("Enter 2nd number:\n")) +print(f"The sum of num1 and num2 is {num1 + num2}") +# Result: The sum of num1 and num2 is 15 + +# [SECTION] Control Structures + +# Control structures can be divided into selection and repetition structures. +# Selection control structures allow a program to choose between options and execute specific code blocks based on the condition. +# Repetition control structures enable a program to repeat certain blocks of code as long as a starting condition is met and until a terminating condition is reached. + +# Selection Control Structures +# If-else statements are used to choose between two or more code blocks depending on the condition. + +test_num1 = 75 + +if test_num1 >= 60: + print("Test passed") +else: + print("Test failed") +# Result: Test passed + +# If-else chains can also be used to provide more than two choices for the program. + +test_num2 = int(input("Please enter the test number:\n")) +if test_num2 > 0: + print("The number is positive") +elif test_num2 == 0: + print("The number is zero") +else: + print("The number is negative") +# Result: +# (15): The number is positive +# (0): The number is zero +# (-15): The number is negative + +# Mini Exercise 1: +# Create an if-else statement that determines if a number is divisible by 3, 5, or both. + # If the number is divisible by both 3 and 5, print "The number is divisible by both 3 and 5." + # If the number is divisible only by 3, print "The number is divisible by 3." + # If the number is divisible only by 5, print "The number is divisible by 5." + # If the number is not divisible by either, print "The number is not divisible by 3 or 5." + +# Solution: +test_div_num = int(input("Please enter a number to test:\n")) +if test_div_num % 3 == 0 and test_div_num % 5 == 0: + print(f"{test_div_num} is divisible by both 3 and 5") +elif test_div_num % 3 == 0: + print(f"{test_div_num} is divisible by 3") +elif test_div_num % 5 == 0: + print(f"{test_div_num} is divisible by 5") +else: + print(f"{test_div_num} is not divisible by both 3 or 5") + +# Repetition Control Structure +# Repetition control structures, also known as loops, allow you to execute a block of code repeatedly. + +# While loops are used to repeatedly execute a block of code as long as a specified condition is true. +print("While Loop:") + +i = 1 +while i <= 5: + print(f"Current count {i}") + i += 1 +# Result: +# Current count 1 +# Current count 2 +# Current count 3 +# Current count 4 +# Current count 5 + +# For Loops in Python are used to iterate over a sequence. + +print("For Loop:") + +fruits = ["apple", "banana", "cherry"] + +for indiv_fruit in fruits: + print(indiv_fruit) +# Result: +# apple +# banana +# cherry + +# To use a for loop to iterate through values, the range() function can be used. +# The range() function is a built-in function in Python used to generate a sequence of numbers. + +print("For Loop with range() function:") + +for x in range(6): + print(f"The current value is {x}") +# Result: +# The current value is 0 +# The current value is 1 +# The current value is 2 +# The current value is 3 +# The current value is 4 +# The current value is 5 + +# range() function with start and stop values +for x in range(6, 10): + print(f"The current value is {x}") +# Result: +# The current value is 6 +# The current value is 7 +# The current value is 8 +# The current value is 9 + +# range() function with start, stop, and step values +for x in range(6, 20, 2): + print(f"The current value is {x}") +# Result: +# The current value is 6 +# The current value is 8 +# The current value is 10 +# The current value is 12 +# The current value is 14 +# The current value is 16 +# The current value is 18 + +# [SECTION] Break Statement +# The break statement is used to stop the loop. + +print("Break Statement in a While Loop:") + +j = 1 + +while j < 6: + print(j) + if j == 3: + break # + j += 1 +# Result: +# 1 +# 2 +# 3 + +# Continue Statement +# The continue statement returns control to the beginning of the loop and continues with the next iteration. + +print("Continue Statement in a While Loop:") + +k = 1 + +while k < 6: + k += 1 + if k == 3: + continue + print(k) +# Result: +# 2 +# 4 +# 5 +# 6 + +# This results in an infinite loop, preventing the program from finishing. + +k = 0 +while k < 6: + if k == 3: + continue + k += 1 + print(k) +# Result: +# 1 +# 2 +# 3 +# .. infinite Loop \ No newline at end of file diff --git a/s03/activity/__pycache__/activity.cpython-312.pyc b/s03/activity/__pycache__/activity.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1be846297316f5e22744660ebf7dffee1f4873f3 GIT binary patch literal 1542 zcma)5&1)N15TCcZl4V&Rv7N|H17$-M(shFDd^jYcl-e@nRMn7{fFf8nyX$Dv)vo$> z71%`-9enVmpq?BEh8$yjX#Rly2f3`MjohWTp3+ki9SS~m-s&TA8cN?`_RY+1-kaZV z=enf(F~5kppg!s9;Pd8mIA^aKH~^9L9Jp zrgM)IgUFz3-NLk`T!BXma7<;I=YAu{m?Iv|}+4UN_B!q&an_HCqD;j5J z3XQ{V7jd0DDiy2WIoMED@f_Q#eq-qy)Oey-H*B?8*DcqnR!ZxoCZ&ejG!^+?X;Z$x zQCeBODX-nFHeJJXs)fR`qdSgaTh6kxa${LhUE_)2dgD!@;e`oVHY~%HW&g}jg2E^g zb+m{bwc$83*UoQC$Jw*^Svo!^w)02aTpx3wjx|7s(TNnhg_~V)$2kqPdpy<$lf(54 zG;WW7KU%09U-my?#E_)viMmB?)6_N5utc|}i~h9Op!OrG)C&?9#v0VH+(^59LfPOt z>`IYNqYYE4LUo+a;{j(!}lhF(-xqzk(e{fSlGXMPB-lf&!lGSzB=O8 z=nUph(PYX*G&gbce`%rslf#9TY@q=BUhI?rLfN1B+7sFAh=wEjNzvXCqZtxUNI~Lh z8tWz|C*m+cTQICG+fR+?GH)I$oQr58nmboI+OF}l(RuJZ`Qqj;#r@)ot1p!xar=n7 z6Ok=TaW)vN16dA}vRt>drpfjxS^lA^n1c*u@1L?~OXtw+LsT4TPnkTCVZ-gP^ftWX zc<$o64B^&EKS{Xa0M3x1ux2XOYYn&l{HEvDY)iaXv#BeVqDSMW2W-SLwp0}T%+OtD zFAM$b&>x_SVp*DwE)U~_M40lMhU>~|^vXXJkp0g0G-!^w?4L(WP7+@X*ndgcoG_i8 zAJM$w2_b){GNkwxn90MLTxaX48hm#9x9pvE>TLo@d?(#8d%4Tq+~wfh=RsULgr(mh zwv*|!dJ9r_K?-t9LHx=gTxHSh(^PM9rMtKiEL;oX*AL;w8$2W3gY#WDe+U program.` + + def career_track(self): + print(f'Currently enrolled in the {self.course_type} program.') + +# 4. Create a method called info that prints the string: `My name is of batch .` + + def info(self): + print(f'My name is {self.name} of batch {self.batch}.') + +# 5. Create an object from the Camper class called zuitt_camper, and pass in values for name, batch, and course_type. + +zuitt_camper = Camper('Alan', 100, 'Python Short Course') + +# 6. Print the values of name, batch, and course_type individually from the zuitt_camper object. + +print(f'Camper Name: {zuitt_camper.name}') +print(f'Camper Batch: {zuitt_camper.batch}') +print(f'Camper Course: {zuitt_camper.course_type}') + +# 7. Execute the info and career_track method of the object. + +zuitt_camper.career_track() +zuitt_camper.info() + +# 8. Update your local session Git repository and push to Git with the commit message "Add activity code s03". +# 9. Add the repository link in Boodle for s03. \ No newline at end of file diff --git a/s03/discussion/discussion.py b/s03/discussion/discussion.py new file mode 100644 index 0000000..5be5b31 --- /dev/null +++ b/s03/discussion/discussion.py @@ -0,0 +1,337 @@ +# [SECTION] Lists +# Lists are similar to arrays in JavaScript in the sense that they can contain a collection of data. +# To create a list, square brackets ([]) are used. + +names = ["John", "Paul", "George", "Ringo"] # String list +programs = ['developer career', 'pi-shape', 'tech career package'] +durations = [260, 180, 20] # Number list +truth_values = [True, False, True, True, False] # Boolean list + +# A list can contain elements of different data types: +sample_list = ["Apple", 3, False, "Potato", 4, True] + +# Problems may arise if you try to use lists with multiple types for something that expects them to be all the same type. + +# Problems may arise if you try to use lists with multiple types for something that expects them to be all the same type. + +print("Lists:") + +# Getting list size +# The number of elements in a list can be counted using the len() function. + +print(len(programs)) +# Result: 3 + +# Accessing values in lists +# List elements can be accessed by providing their index number. +# Indexing in lists starts at 0 and goes up to n - 1, where n is the number of elements. + +print(names[0]) +# Result: John + +# Accessing the last item in the lists +print(names[-1]) +# Result: Ringo + +# Accesing the whole list +print(durations) +# Result: [260, 180, 20] + +# Accessing a range of values +# SYNTAX: list[start index : end index] +print(programs[0:2]) +# Result: ['developer career', 'pi-shape'] + +# Mini Exercise 1: +# Create a list of names of 5 students +# Create a list of grades for the 5 students +# Use a loop to iterate through the lists, printing in the following format: "The grade of is ". + +# Solution: +students = ["Mary", "Matthew", "Tom", "Anna", "Thomas"] +grades = [100, 85, 88, 90, 75] + +count = 0 +while count < len(students): + print(f"The grade of {students[count]} is {grades[count]}") + count += 1 + +# Result: +# The grade of Mary is 100 +# The grade of Matthew is 85 +# The grade of Tom is 88 +# The grade of Anna is 90 +# The grade of Thomas is 75 + +# Updating List Elements + +# Print the current value +print(f'Current value: {programs[2]}') +# Result: Current value: tech career package + +# Update the value +programs[2] = 'short courses' + +# Print the new value +print(f'New value: {programs[2]}') +# Result: New value: short courses + +# [SECTION] List Manipulation +# Lists have methods that can be used to manipulate their elements. + +# Adding list items – the append() method allows you to insert items at the end of the list. + +programs.append('global') +print(programs) +# Result: ['developer career', 'pi-shape', 'Short Courses', 'global'] + +# Deleting list items – the "del" keyword can be used to delete elements from the list. + +# Add a new item to the durations list +durations.append(360) +print(durations) +# Result: [260, 180, 20, 360] + +# Delete the last item on the list +del durations[-1] +print(durations) +# Result: [260, 180, 20] + +# Membership Checks – The "in" keyword checks if an element is in the list and returns True or False. +print(20 in durations) +# Result: True +print(500 in durations) +# Result: False + +# Sorting lists - the sort() method sorts the list alphanumerically, ascending, by default. +names.sort() +print(names) +# Result: ['George', 'John', 'Paul', 'Ringo'] + +# Emptying the list - the clear() method is used to empty the contents of the list. +test_list = [1, 3, 5, 7, 9] +print(test_list) + +test_list.clear() +print(test_list) +# Result: [] + +# [SECTION] Dictionaries +# Dictionaries are used to store data values in key:value pairs. This is similar to objects in JavaScript. +# A dictionary is a collection that is ordered, changeable, and does not allow duplicates. +# Ordered means that the items have a defined order, and that order will not change. +# Changeable means that values can be modified. +# To create a dictionary, curly braces ({}) are used, and key-value pairs are written as key: value. + +print("Dictionaries:") + +person1 = { + "name" : "Brandon", + "age" : 28, + "occupation" : "student", + "is_enrolled" : True, + "subjects" : ["Python", "SQL", "Django"] +} + +# To get the number of key-pairs in the dictionary, the len() method can be used. +print(len(person1)) +# Result: 5 + +# To get a value from the dictionary, you can refer to its key using square brackets ([]). +print(person1["name"]) +# Result: Brandon + +# The keys() method returns a view object containing all the keys in the dictionary. +print(person1.keys()) +# Result: dict_keys(['name', 'age', 'occupation', 'is_enrolled', 'subjects']) + +# The values() method returns a view object containing all the values in the dictionary. +print(person1.values()) +# Result: dict_values(['Brandon', 28, 'student', True, ['Python', 'SQL', 'Django']]) + +# The items() method returns each item in the dictionary as key-value pairs in a view object. +print(person1.items()) +# Result: dict_items([('name', 'Brandon'), ('age', 28), ('occupation', 'student'), ('is_enrolled', True), ('subjects', ['Python', 'SQL', 'Django'])]) + +# Adding key-value pairs can be done either by assigning a new key using square brackets, or by using the update() method. + +# Using new index +person1["nationality"] = "Filipino" +print(person1) +# Result: {'name': 'Brandon', 'age': 28, 'occupation': 'student', 'is_enrolled': True, 'subjects': ['Python', 'SQL', 'Django'], 'nationality': 'Filipino'} + +# Using update() method +person1.update({"fav_food" : "Sinigang"}) +print(person1) +# Result: {'name': 'Brandon', 'age': 28, 'occupation': 'student', 'is_enrolled': True, 'subjects': ['Python', 'SQL', 'Django'], 'nationality': 'Filipino', 'fav_food': 'Sinigang'} + +# Deleting entries can be done using the pop() method or the del keyword + +# Using pop() method +person1.pop("fav_food") +print(person1) +# Result: {'name': 'Brandon', 'age': 28, 'occupation': 'student', 'is_enrolled': True, 'subjects': ['Python', 'SQL', 'Django'], 'nationality': 'Filipino'} + +# Using del keyword +del person1["nationality"] +print(person1) +# Result: {'name': 'Brandon', 'age': 28, 'occupation': 'student', 'is_enrolled': True, 'subjects': ['Python', 'SQL', 'Django']} + +# Emptying the Dictionary + +person2 = { + "name" : "John", + "age" : 18 +} + +print(person2) +# Result: {'name': 'John', 'age': 18} + +# The clear() method empties the dictionary +person2.clear() + +print(person2) +# Result: {} + +# Looping through dictionaries +print("Looping through dictionaries:") + +for key in person1: + print(f"The value of {key} is {person1[key]}") + +# Result: +# The value of name is Brandon +# The value of age is 28 +# The value of occupation is student +# The value of is_enrolled is True +# The value of subjects is ['Python', 'SQL', 'Django'] + +# Nested dictionaries - dictionaries can be nested inside each other +person3 = { + "name": "Monika", + "age": 20, + "occupation": "poet", + "is_enrolled": True, + "subjects": ["Python", "SQL", "Django"] +} + +classroom = { + "student1" : person1, + "student2" : person3 +} +print(classroom) +# Result: {'student1': {'name': 'Brandon', 'age': 28, 'occupation': 'student', 'is_enrolled': True, 'subjects': ['Python', 'SQL', 'Django']}, 'student2': {'name': 'Monika', 'age': 20, 'occupation': 'poet', 'is_enrolled': True, 'subjects': ['Python', 'SQL', 'Django']}} + +# [SECTION] Functions +# Functions are blocks of code that run when called. +# The "def" keyword is used to create a function. +# SYNTAX: def function_name(): + +def my_greeting(): + # Code to be run when my_greeting is called + print('Hello User!') + +print("Functions:") + +# Calling/invoking a function +my_greeting() +# Result: Hello User! + +# Parameters in functions allow you to specify what inputs the function expects and provide more control over how the function behaves. +def greet_user(username): + # prints out the value of the username parameter + print(f'Hello, {username}!') + +# Arguments are the actual values that are passed into the function when it is called. +greet_user("Bob") +# Result: Hello, Bob! +greet_user("Amy") +# Result: Hello, Amy! + +# The "return" keyword allows a function to return values. +def addition(num1, num2): + return num1 + num2 + +sum = addition(5, 10) +print(f"The sum is {sum}") +# Result: The sum is 15 + +# A lambda function is a small, anonymous function that can be used for callbacks or short, throwaway operations. +# It works like any regular Python function, but it has no name and is defined using a single line of code. +# A lambda function can take any number of arguments but can only contain one expression. + +greeting = lambda person : f'Hello {person}!' +print(greeting("Jane")) +# Result: Hello Jane! + +multiplication = lambda a, b : a * b +print(multiplication(3, 5)) +# Result: 15 + +# Mini Exercise 2: +# Create a function that returns the square of a number. +# Use 5 as argument, result should be 25. +# Print "The square is {result}." + +# Solution: +def sqr(num): + return num * num # or return num ** 2 + +result = sqr(5) +print(f"The square is {result}.") +# Result: The square is 25. + +# [SECTION] Classes +# Classes serve as blueprints that describe the concept of objects. +# Each object has characteristics (called properties) and behaviors (called methods). +# Imagine the concept of a car: a car has a brand, model, and year of make, and it can drive, brake, and turn. +# To create a class, use the "class" keyword followed by a class name that starts with an uppercase letter. +# SYNTAX: class ClassName(): + +class Car(): + # The properties that all Car objects must have are defined in a method called __init__. + # Any number of parameters can be passed to __init__(), but the first parameter should always be self. + # self refers to the current instance of the class + # When a Car instance is created, that instance is automatically passed to the self parameter. + def __init__(self, brand, model, year_of_make): + self.brand = brand + self.model = model + self.year_of_make = year_of_make + + # Other properties can be added and assigned hard-coded values. + self.fuel = "Gasoline" + self.fuel_level = 0 + + # Methods are functions defined inside a class. + # Method to simulate filling the fuel tank + def fill_fuel(self): + print(f'Current fuel level: {self.fuel_level}') + print('filling up the fuel tank...') + self.fuel_level = 100 + print(f'New fuel level: {self.fuel_level}') + # Mini Exercise solution + def drive(self, distance): + print(f"The car has driven {distance} kilometers") + print(f"The fuel level left: {self.fuel_level - distance}") + +# Creating a new instance is done by calling the class and providing the required arguments +new_car = Car("Nissan", "GT-R", "2019") + +print("Classes:") + +# Displaying attributes can be done using dot notation +print(f"My car is a {new_car.brand} {new_car.model}") +# Result: My car is a Nissan GT-R + +# Calling methods on the instance +new_car.fill_fuel() +# Result: +# Current fuel level: 0 +# filling up the fuel tank... +# New fuel level: 100 + +# Mini Exercise solution +new_car.drive(50) +# Result: +# The car has driven 50 kilometers +# The fuel level left: 50 \ No newline at end of file diff --git a/s04/activity/__pycache__/activity.cpython-312.pyc b/s04/activity/__pycache__/activity.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..119e106873250da79fe3ed5b12a6e86985ad7b34 GIT binary patch literal 4472 zcmcgv-EY)J5Z}GC?|fhRC?SME!ABC{TAF|gv=rKs4?fifL_k#6sIECX;lh2;wU73W zJOn8f7m29hp-Lo##B0Q#(w9^aHL_ZXs!zND7qy6|&aBUlbC*IPYWHD0v%B8k?Ck7s z?4M$>FoE{lFXt{l3K8-L8cq|dN~MnyGD|d~(G1DbB+dGgK1zJ#1krqxMDy$PzTcjk z^z&W;dPUvu_6oc=0KGv^ujnJXph;Rt3%fG|dSI;4abV@CMec(S*eHP+&9?59_p1gU z-{2jw^_6iz6}6}q(;8gVupV9$wb6qbeg$fH?4_v1rbP2&bS2@l{JnksR)c!UFqxV% zv$}aXucf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