python coding problem and logical operation

Posted by sonnieboy on Mon, 21 Oct 2019 22:59:41 +0200

1. Review yesterday's courses and assignments

 1 #1.Use while Cycle input 1 2 3 4 5 6 8 9 10
 2 
 3 '''
 4 count = 0
 5 while count < 10:
 6   count += 1 # count = count +1 
 7   if count == 7:
 8      print(' ') 
 9   else: 
10     print(count) 
11 #Second method 
12 
13 count = 0 
14 while count < 10: 
15   count += 1 # count = count +1 
16   if count == 7: 
17     continue 
18     print(count) 
19 
20 '''
21 #3,Output 1-100 All odd numbers in
22 #Method 1:
23 # count = 1
24 # while count < 101:
25 #     print(count)
26 #     count += 2
27 #Method two:
28 # count = 1
29 # while count < 101:
30 #     if count % 2 == 1:
31 #         print(count)
32 #     count += 1
33 
34 #5,Seek 1-2+3-4+5 ... 99 Sum of all numbers of
35 # sum = 0
36 # count = 1
37 # while count < 100:
38 #     if count % 2 == 0:
39 #         sum = sum - count
40 #     else:
41 #         sum = sum + count
42 #     count += 1
43 # print(sum)
44 
45 #6,User login (three retries)
46 #input I have an account and password in my heart while
47 
48 i = 0
49 while i < 3:
50     username = input('Please enter your account number:')
51     password = int(input('Please input a password:'))
52     if username == 'Salted fish brother' and password == 123:
53         print('Login successfully')
54     else:
55         print('Login failed, please login again')
56     i += 1

2. Format output

#Format output
# % s d
# name = input('Please enter a name')
# age = input('Please enter age')
# height = input('Please enter height')
# msg = "My name is%s,This year%s height %s" %(name,age,height)
# print(msg)
"""
name = input('Please enter a name:')
age = input('Please enter age:')
job = input('Please enter work:')
hobbie = input('Your hobby:')

msg = '''------------ info of %s -----------
Name  : %s
Age   : %d
job   : %s
Hobbie: %s
------------- end -----------------''' %(name,name,int(age),job,hobbie)
print(msg)
"""
name = input('Please enter a name')
age = input('Please enter age')
height = input('Please enter height')
msg = "My name is%s,This year%s height %s Learning progress is 3%%s" %(name,age,height)
print(msg)

3. while else loop statement

count = 0
while count <= 5 :
    count += 1
    if count == 3:break
    print("Loop",count)

else:
    print("The cycle is running normally.")
print("-----out of while loop ------")

4. Initial coding

 1 NEW
 2 open
 3 one
 4 families
 5 look
 6 look
 7 A B C
 8 01000010 01000011
 9. The transmission and storage of telegrams and computers are 01010101.
10 
11 the earliest 'codebook' ascii covers the case of English letters, special characters and numbers.
12 ascii can only represent 256 possibilities, too few.
13 founded unicode
14 16 means one character is not good, 32 bits means one character.
15     A  01000001010000010100000101000001
16     B  01000010010000100100001001000010
17 I 0100001001000010010010001000010010001000010001000010001000010000010000010000010
18 Unicode upgrade UTF-8 utf-16 UTF-32
19 8 bits = 1 byte
20 UTF-8 a character is represented by at least 8 bits, and English is represented by 8 bits and a byte
21 European characters use 16 bits to represent two bytes
Chinese uses 24 bits to represent three bytes
23 utf-16 a character is represented by at least 16 bits
24 
25 gbk invented by the Chinese themselves, a Chinese is represented by two bytes and 16 bits.
26 
27 1bit    8bit = 1bytes
28 1byte   1024byte = 1KB
29 1KB     1024kb = 1MB
30 1MB     1024MB = 1GB
31 1GB     1024GB = 1TB

5. Logical operation

 1 #and or not
 2 #Priority, ()> not > and > or
 3 # print(2 > 1 and 1 < 4)
 4 # print(2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2)
 5 # T or T or F
 6 #T or F
 7 # print(3>4 or 4<3 and 1==1)  # F
 8 # print(1 < 2 and 3 < 4 or 1>2)  # T
 9 # print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)  # T
10 # print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)  # F
11 # print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)  # F
12 # print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
13 
14 #ps  int  ----> bool   Nonzero to bool True   0 convert to bool yes False
15 # print(bool(2))
16 # print(bool(-2))
17 # print(bool(0))
18 # #bool --->int
19 # print(int(True))   # 1
20 # print(int(False))  # 0
21 
22 
23 '''x or y x True,Then return x'''
24 # print(1 or 2)  # 1
25 # print(3 or 2)  # 3
26 # print(0 or 2)  # 2
27 # print(0 or 100)  # 100
28 
29 
30 # print(2 or 100 or 3 or 4)  # 2
31 
32 # print(0 or 4 and 3 or 2)
33 '''x and y x True,Then return y'''
34 # print(1 and 2)
35 # print(0 and 2)
36 print(2 or 1 < 3)
37 print(3 > 1 or 2 and 2)

Topics: PHP ascii