Skip to content

Commit b184d54

Browse files
committed
section3 final
1 parent 7948e5a commit b184d54

38 files changed

+271
-0
lines changed

Section3/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Section3/.idea/Section3.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Section3/.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Section3/.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Section3/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Section3/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Section3/lecture31/Program1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# program to declare and use numbers in Python
2+
var1 = 123
3+
print(type(var1), " value = ",var1)
4+
var2 = 12.23
5+
print(type(var2), " value = ",var2)
6+
var3 = 10e10 # we can use exponents
7+
print(type(var3), " value = ",var3)
8+
var4 = 10+20j # we can use complex num
9+
print(type(var4), " value = ",var4)
10+

Section3/lecture31/Program2.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Program to show differnt type of number system
2+
bin = 0b11101
3+
print("Value of bin = ", bin)
4+
oct = 0o432
5+
print("Value of oct = ", oct)
6+
hex = 0xFFF
7+
print("Value of hex = ", hex)

Section3/lecture31/Program3.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Program to show type conversion
2+
var1 = 12.23
3+
var2 = int(var1)
4+
print(var2)
5+
var3 = 12
6+
var4 = float(var3)
7+
print(var4)
8+
var5 = "12.23"
9+
var6 = float(var5)
10+
print(var6)
11+

Section3/lecture31/Program4.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Program to show number functions
2+
3+
print("abs() = ", abs(-12))
4+
print("max() = ", max(10, 2, 33, 44, 55, 11, 78))
5+
print("min() = ", min(10, 2, 33, 44, 55, 11, 78))
6+
print("round() = ", round(10.3459,2))

Section3/lecture31/__init__.py

Whitespace-only changes.

Section3/lecture32/Program1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Program to show boolean data type
2+
var1 = True
3+
print("type = ", type(var1), ", Value = ", var1)
4+
var2 = False
5+
print("type = ", type(var2), ", Value = ", var2)

Section3/lecture32/Program2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Program showing use of bool()
2+
3+
var1 = bool(1)
4+
print("var1 = ", var1)
5+
var2 = bool(0)
6+
print("var2 = ", var2)
7+
var3 = bool("Hello")
8+
print("var3 = ", var3)
9+
var4 = bool("")
10+
print("var4 = ", var4)
11+
12+
13+

Section3/lecture32/__init__.py

Whitespace-only changes.

Section3/lecture33/Program1.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Program to show different string declaration syntax
2+
3+
str1 = "Hello world Double quotes"
4+
str2 = 'Hello world single quotes'
5+
str3 = """ Line1
6+
line2
7+
line3 Triple double quotes"""
8+
str4 = ''' Line1
9+
line2
10+
line3 Triple single quotes'''
11+
print("str1 = ", str1)
12+
print("str2 = ", str2)
13+
print("str3 = ", str3)
14+
print("str4 = ", str4)

Section3/lecture33/Program2.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Program to show different string methods
2+
3+
str1 = "hello world"
4+
print("length of str = ", len(str1))
5+
print("index() = ", str1.index("world"))
6+
print("find() = ", str1.find("w"))
7+
print("capitalize() = ", str1.capitalize())
8+
9+
10+

Section3/lecture33/Program3.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Program to show more String methods
2+
str2 = "M"
3+
print("isalpha() = ", str2.isalpha())
4+
str3 = "David"
5+
print("join() = ", str3.join("[]"))
6+
print("replace() = ", str3.replace("David","Paul"))
7+
str4 = "Apple,Orange,Banana"
8+
print("split() = ", str4.split(","))
9+
print("upper() = ", str4.upper())
10+
11+
12+
13+
14+
15+
16+

Section3/lecture33/Program4.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Program to show indexing of string
2+
3+
str1 = "Welcome to Python"
4+
print("indexing first position", str1[0])
5+
print("indexing last position = ", str1[len(str1)-1])
6+
print("negative indexing = ", str1[-1])

Section3/lecture33/Program5.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Program to show slicing string in Python
2+
3+
str1 = "My name is David"
4+
print("slicing string 1 = ", str1[:2])
5+
print("slicing string 2 = ", str1[3:7])
6+
print("slicing string 3 = ", str1[8:])
7+
str2 = "abcdefgh"
8+
print("slicing string with step size = ", str2[::2])
9+
print("reversing string = ", str2[::-1])

Section3/lecture33/Program6.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Program to show different print formatting
2+
3+
print("Hello {}".format("David"))
4+
print("format = {0} {2} is {1}".format("My", "David", "Name"))
5+
# using fstring
6+
str1 = "David"
7+
print(f" fstring = My name is {str1}")

Section3/lecture33/__init__.py

Whitespace-only changes.

Section3/lecture34/Program1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Program to show declaration and usage of lists
2+
3+
fruits_list = ["Apple", "Orange", "Banana", "Mango"]
4+
print(" fruits_list = ", fruits_list)
5+
print("iterating list items")
6+
for item in fruits_list:
7+
print("fruit : ", item)
8+
list1 = [] # empty list
9+
print("length of list1 = ", len(list1))

Section3/lecture34/Program2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Program to show indexing and slicing a list
2+
3+
name_list = ["David", "Paul", "Sam", "Adam"]
4+
print("name_list first element = ", name_list[0])
5+
print("name_list last element = ", name_list[-1])
6+
print("name_list slicing first 2 elements = ", name_list[0:2])
7+
print("name_list reversing elements = ", name_list[::-1])
8+

Section3/lecture34/Program3.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Program to show list methods
2+
3+
cars = ["Skoda", "Toyota", "Ferrari", "BMW"]
4+
print("list index ", cars.index("BMW"))
5+
cars.append("Ford")
6+
print(" after append = ", cars)
7+
print(" after pop = ", cars.pop())
8+
cars.remove("Skoda")
9+
print(" after remove = ", cars)
10+
cars.insert(2, "Fiat")
11+
print(" after insert = ", cars)
12+
cars.clear()
13+
print(" after clear = ", cars)

Section3/lecture34/__init__.py

Whitespace-only changes.

Section3/lecture35/Program1.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Program to show declaration and usage of tuples
2+
3+
days = ("sun", "mon", "tue", "wed", "thu", "fri", "sat")
4+
print("Tuple days = ", days)
5+
emp = () # empty tuple
6+
print("empty tuple =", emp)
7+
tup = (1,) # empty tuple
8+
print("single element tuple =",tup)

Section3/lecture35/Program2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Program showing useage of 'in' with tuples
2+
3+
days = ("sun", "mon", "tue", "wed", "thu", "fri", "sat")
4+
if "mon" in days:
5+
print("mon is present")
6+
7+
if "jan" not in days:
8+
print("jan is not present")

Section3/lecture35/Program3.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Program to show tuple unpacking in Python
2+
3+
items = ("pen", "box", "ball", "paper")
4+
(red, green, yellow, blue) = items
5+
print("red = ",red)
6+
7+
list1 = [(1, 2), (3, 4), (5, 6)] # llist of tuples
8+
for (a, b) in list1:
9+
print("(",a,",", b, ")")

Section3/lecture35/Program4.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Program to show indexing and slicing a tuple
2+
3+
tup1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
4+
print("first element ", tup1[0])
5+
print("last element ", tup1[-1])
6+
print("Slicing first 5 elements = ", tup1[:5])
7+
print("Slicing last 5 elements = ", tup1[5:])
8+
print("Slicing elements with step 2 = ", tup1[::2])

Section3/lecture35/__init__.py

Whitespace-only changes.

Section3/lecture36/Program1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Program to show declaration of sets in python
2+
3+
set1 = {1, 2, 3, 4, 5, 6, 7, 8, 9}
4+
print("set1 = ", set1)
5+
set2 = set() # empty set
6+
print(type(set2))
7+
set3 = {1,}
8+
print("single element set = ", set3)
9+
set4 = set(["a","b", "c"])
10+
print("set4 = ", set4)
11+

Section3/lecture36/Program2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Program to show methods of set
2+
3+
set1 = {1, 2, 3, 4}
4+
set1.add(5)
5+
print("after add = ", set1)
6+
set2 = {6, 7, 8, 9}
7+
print("union = ", set1.union(set2))
8+
set3 = {4, 5, 6, 7}
9+
print("intersection = ", set2.intersection(set3))
10+
set1.discard(1)
11+
print("after discard = ", set1)

Section3/lecture36/Program3.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Program to show frozen sets
2+
3+
set1 = frozenset({1, 2, 3, 4, 5})
4+
print("Frozen set = ", set1)

Section3/lecture36/__init__.py

Whitespace-only changes.

Section3/lecture37/Program1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Program to show declaration and usage of dictionaries
2+
3+
dict1 = {"name": "David", "age": 31, "job": "instructor"}
4+
print("dict1 = ", ict1)
5+
print("dict1 name = ", dict1["name"])
6+
dict2 = {} # empty dictionary
7+
print("empty dictionary = ", dict2)
8+
dict1["age"] = 32
9+
print("dict1 after changing name ", dict1)

Section3/lecture37/Program2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Program to show dictionary methods
2+
3+
dict1 = {"name": "David", "age": 31, "job": "instructor"}
4+
print("keys : ", dict1.keys())
5+
print("values : ", dict1.values())
6+
for (k,v) in dict1.items():
7+
print(k, " -> ", v)
8+

Section3/lecture37/__init__.py

Whitespace-only changes.

Section3/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This is a sample Python script.
2+
3+
# Press Shift+F10 to execute it or replace it with your code.
4+
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
5+
6+
7+
def print_hi(name):
8+
# Use a breakpoint in the code line below to debug your script.
9+
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
10+
11+
12+
# Press the green button in the gutter to run the script.
13+
if __name__ == '__main__':
14+
print_hi('PyCharm')
15+
16+
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

0 commit comments

Comments
 (0)