#print("Hello World!") #print("hi")
#def a ():
""" docstring print("hi")
#rghrinrtjj = 1
#
#
#
"""
#X = 1
#help(a)
#Variable
#print(id(1)) # need resigster
#z = x = y = 1 # coding reading from right to left
#x = 2
#print(id(x), id(y), id(z), id(1))
#_a = 1 + 1
#a_b_able = 1
#one_two_three = '123'
#a = 1
#A = 1
#A1 = 1
#print(_)
#a = 1
#A = 1 #"1" = literal
#a = 1 #integer
#print(type(a))
#a = 'hello'# string
#print(type(a))
#a = 1.0
#print(type(a))
#print(0.5-0.4)
#print(0.1 + 0.1 + 0.1)
#print(0.1 + 0.1 + 0.1 + 0.1)
#print(0.1 + 0.1 + 0.1 + 0.1 + 0.1)
#print('hello')
#print("Hello, World!!!")
#print("""Hi Madam,
#my name is Chan Tai Man.""")
#country = ['China','France','United States','India', 'Germany']
#if 'France 'in country :
#print('France is in the list')
#else:
#print('France is Not in the list')
#x = print(1 + 1)
#Variable
#print(id(1)) # need resigster
#z = x = y = 1 # coding reading from right to left
#x = 2
#print(id(x), id(y), id(z), id(1))
#a = 1
#b = c = a
#print(a)
#print(b)
#print(c)
#a = 2 # a = 2 will cover the value of a = 1
#print(a)
#print(b)
#print(c)
#nation = 'China'
#age = 23
#print(type(nation))
#print(type(age))
a = 'Hi everyone, my name is Chan Tai Ming.'
#print('1:', a)
#print('2:', a[0])
#print('3:', a[-1])
#vs
#print(a)
#print(a[0])
#print(a[-1])
#print('1:', a[:])
#print('2:', a[:-1])
#print('1: It is Joe\'s belongings')
#x = 1 # integer
#y = 1.0 # float
#yy = 1e10 # float 1x10^10 , "e" 是科學數字
#z = 1 + 10j # complex
#print(type(x), type(y), type(yy), type(z))
# Precedence and Associativity of Operators in Python(can check the details)
#x = 1 + 1 # 2 x operator # x = 2 # notes p. 65
# x =1 + 1 *2 **(2 + 1)
# print(x) # https://www.w3schools.com/python/
#x = 1
#y = float(x)
#print(type(y))
#print(type(x))
#x ='s'
#y = 'hello'
#z ='1 prince street' # string cuz have ''
#print(type(x), type(y), type(z))
#print(y.upper(), x.upper())
#print(y.capitalize()) # note P. 27-28 *will happen in exam
#x ='s'
#y = 'hello'
#z ='1 prince street'
#print(x + y)
#print(x * 2)
#print(z * 4)
#print(type(str(a)))
#x = True
#y = False
#print(bool(0), bool(1), bool(-1)) # only 0 is False
#print(bool(''), bool('a'))
#print(bool(0.0), bool(1.0))
#x = None
#print(bool(None))
#print(print('hello')) # print value = none
#name = ['John', 'Mary', [1,2,3], 1, [6,7,8] , [9,[12,13,14],11]]
#name[5][1][2]= 'Peter'
#print(name)
#person ={'name' : 'John', 'age' : 20, 'gender' : 'male'}
#person ={'name' : 'John', 'age' : '20', 'gender' : 'male'}
#person['age'] = 21
#print(person)
#person['address']='1 prince street'
#print(person)
#del person ['gender']
#print(person)
#1X MC, 1 long q (Exam)
#print(name[0], name[3])
#name[3]='David'
#name[2][1] ='Peter'
#name[4] = 'Ryan'
#name[1][1]='b'# can't change the part of it, also the sequence
#print(name[1][1])
#x = [1,2] # tuple to list need add '[]', then can override the past record
#print(x)
#print(x[0], type(x))
#x[0] = 3
#Tuple
#y = 1,
#print(y, type(y))
#a,b = 1,2 # tuple = tuple
#(a,b)= 1,(2,3)
#print(a,b, type(a), type(b))
#rint(a,type(a))
#print(a,b, type(a), type(b), b[0], b[1],type(b[0]), type(b[1]))
#Set
x ={1,2,'b',4,'a',1,1,1,'a',3,4,4,6,6,6,7,7,7,9}
#print(x) # only keep the unique value, print out result is not in order
# before 3.8 Dictionary is not in order same like set
#notes p.65
#for - repeating time is determined
#while() - repeating time is unknown
# case 1 : controller inside while loop
x = 1
while(True):
print(x)
x = x + 1
# add a controller
if(x == 3):
# break # if x = 3 then break the loop
print(x)
continue
x = x + 1
if (x == 7):
break
# else can follow by while loop
else :
print("loop exit normally")
# case 2 : controller at while conditional experssion
while (x < 10):
print("second while loop", x)
x = x + 1
else:
print("second loop exit normally")
# for : loop iterable, range(), list[], tuple()
# case 1 : loop a list / tuple
#y = [1, 2, 3, 4] # put 1 into i/ put 2 into i/put 3 into i/put 4 into i, maximum test 4 times
#for i in y:
# if (i == 3):
#break
#print(i)
#continue
#print(i)
# case 2 : range () - range(start, end-1, step)
#for i in range(0,10,1):
#print("loop", i)
#for i in range(0,10,3): # start = 0, 0 + step = (3), 3 + step = (6), 6 + step = (9)
#for i in range(4,31,7): #[4, 11, 18, 25]
#print(i)
#for i in range(4, 31) : # step = 1
# print(i)
#for i in range(31):# start = 0, step = 1
#print(i) # i = 1
#for i in range(30,0,-3): #if negative then stop by 0, one value before the target value
# print(i)
#for i in range(30,33,-2): # can't function #[]
#print(i)
#sub - list, slice() - 0:10:1
#z = [0,1,2,3,4,5,6,7,8,9,10]
#print(z[0:10:1])
#print(z[:6]) #start = 0, 6-1 = 5, step =1
#print(z[3:1:1]) # empty [], asume is 3 + step
#print(z[-1:-4:-1])
#a = "hello world"
#print(a[-1:-4:-1])
# note p.38
x = 1
y = '0'
try:
result = x > y
print(result)
except TypeError:
print("data type error")
except ZeroDivisionError:
print("Y can't be zero")
x = 10
print(x)
#from dio import b,x
import dio as lib
def a():
print("I am from function a")
a()
lib.b()
print(lib.x)
#expression_ result = (7 - 4) + (((3 * 6) / (2 ** 2)) % 5)
#expression_ result = (((10 + (3 * 2)) < 20) and ((15 % 4 )== 3)) or (not ((5 - (3 * 2)) > 0)) # % = 餘除 , // = 整除
#result = (not ((10 // 3))== 3)) or ((((8 % 3) + 1) == 3) and ((7 | 2) > 5)) # | = bit e.g., 1010, "0" = bit , 讀 7 or 2 , (7 | 2) is equal to 7
#result4 = 5 + 3 if 2 ** 3 > 7 else 4 * 6 if 7 < 8 else 5 - 10 / 2
#result2 = ((10 > 5) and (((3 * 3) + 1 )<= 10)) or ((not (5 != 5)) and (4 * 2))
#result1 = 3 + 5 ** 2 & 15 | 2 ** 3 if 8 % 3 > 1 else 1 ^ 7 & 4
#print(xpression_ result)
#leapyear: year is muliple of 4 and not multiple of 100 or year is multiple of
#year = 2008
#1
lst = [0, 1,2 ,3, 4, 5]
print(1st[1:4]) 1, 2, 3
#2
lst = [0, 1, 2, 3, 4, 5]
print(1st[:3]) 0, 1, 2
#3
lst = ["a", "b", "c", "d"]
print(1st[2:]) c, d ( : untill the end)
#4
lst = [10, 20, 30, 40, 50]
print(1st[:-2]) 10, 20, 30
#5
lst = ["apple", "banana", "cherry", "date"]
print(1st[-2:]) cherry, date
#6
lst = [0, 1, 2, 3, 4, 5]
print(1st[::2]) 0, 2, 4 ( 0 + 2 + 2 / :: skip 2 column)
#7
lst = ["p", "y", "t", "h", "o", '"n"]
print(lst[::-1]) n, o, h, t, y, p
#8
lst = [0, 1, 2, 3, 4, 5]
print(lst[4:1:-1]) 4, 3, 2
#9
lst = [0, 1, 2, 3, 4, 5]
print(lst[-2:-5:-1]) 4, 3, 2
#10
lst = [10, 20, 30, 40]
print(lst[::-2]) 40, 20
# 11
lst = [0, 1, 2]
print(lst[5:]) # ans = empty list
#12
lst = ["a", "b", "c", "d"]
print(lst[3:1]) # ans = empty list *only can move 1 direction
#But 3 > 1, so moving forward from 3 can never reach 1
#This creates an impossible range, so Python returns an empty list
#13
lst = [0, 1, 2, 3, 4]
print(lst[3:0:-1]) 3,2,1
#14
s ="hello"
print(s[::-1]) 'o','1','1','e','h'
#15
lst = [0, 1, 2, 3, 4, 5, 6]
print (lst[::3]) 0, 3, 6
#Slice = [start:stop:step]
#step seems only use to determine方向
# Extract file extension
filename = "document.pdf"
extension = filename[-3:] pdf
# Get first and last elements
items = ["first", "second", "third", "last"]
first_item = items[0] first
last_item = items[-1] last
# Reverse a list
original = [1, 2, 3, 4, 5]
reversed_list = original[::-1] 5,4,3,2,1
# Get every other element
data = [10, 20, 30, 40, 50, 60]
alternating = data[::2] 10, 30, 50
# Extract substrings
sentence = "The quick brown fox"
words = sentence[4:9] quick
answer:
# Extract file extension
filename = "document.pdf"
extension = filename[-3:] # "pdf"
# Get first and last elements
items = ["first", "second", "third", "last"]
first_item = items[0] # "first"
last_item = items[-1] # "last"
# Reverse a list
original = [1, 2, 3, 4, 5]
reversed_list = original[::-1] # [5, 4, 3, 2, 1]
# Get every other element
data = [10, 20, 30, 40, 50, 60]
alternating = data[::2] # [10, 30, 50]
# Extract substrings
sentence = "The quick brown fox"
words = sentence[4:9] # "quick"