Practice
#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)
INFO