4.27
01, pycharm installation and use.
011, a review of the content of yesterday.
Compiled:
Compile the code into a binary all at once, and then run it.
Advantages: high execution efficiency.
Disadvantages: low development efficiency, not cross-platform.
C
Explanation:
The code is explained line by line, executing as it is interpreted.
Advantages: high development efficiency and cross-platform.
Disadvantages: low execution efficiency.
python
variable:
1, must be any combination of alphanumeric underscores.
2. Numbers cannot start.
3, cannot be a keyword in Python.
4. It cannot be in Chinese.
5, not too long.
6. Be descriptive.
Constant: A variable that cannot be changed. All uppercase variables are constants and are placed at the beginning of the file.
Basic data type:
int : Operation.
str:
Anything enclosed in quotes is a string.
+ stitching. str + str
* str * int。
bool
True,False
User input: input
python2x: raw_input()
input() is equivalent to eval()
python3x: input()
if
if condition:
pass
if condition:
pass
else:
pass
if condition:
pass
elif condition:
pass
elif condition:
pass
if condition:
pass
elif condition:
pass
elif condition:
pass
else:
pass
if condition:
if ...
else:
pass
else:
if..
else:...
while condition:
pass
break: Jump out of the current loop directly.
continue: End this loop and continue to the next loop.
012, homework explanation.
'''
1. Use the while loop to input 1 2 3 4 5 6 8 9 10
2. Find the sum of all numbers from 1 to 100
3. Output all odd numbers within 1-100
4. Output all even numbers within 1-100
5. Find the sum of all numbers 1-2+3-4+5 ... 99
6. User login (three chances to retry)
'''
# 1. Use the while loop to input 1 2 3 4 5 6 8 9 10
# count = 1
# while count < 11:
# if count == 7:
# count += 1
# print(count)
# count += 1
# 5. Find the sum of all numbers 1-2+3-4+5 ... 99
# sum = 0
# count = 1
# while count < 100:
# if count % 2 == 0:
# sum = sum - count
# else:
# sum = sum + count
# count += 1
# print(sum)
# 6. User login (three chances to retry)
# i = 0
# while i < 3:
# username = input('Please enter username:')
# password = input('Please enter your password:')
# if username == '婉容' and password == '123':
# print('Login successful')
# break
# else:
# print('Username or password is incorrect, please re-enter')
# i += 1
02, format the output. %s %d
03,while else
04, operator.
05, first acquaintance with coding.
Spy Movie: Didi Didi Hi-Lo, 0101010
Computer file storage, and file transfer 010101010
Primary codebook: ascii letters, numbers, special characters.
0000 0001 8 bits == 1 byte One byte represents one character.
Character: The smallest unit that makes up content. abc a b c
China China
a 01100001
b 01100010
c 01100011
Universal code: unicode
Created initially 16-bit two bytes representing a character.
a :01100001 01100001
Middle: 01100011 01100001
Upgrade: 32-bit four bytes represent a character.
a :01100001 01100001 01100001 01100001
Medium: 01100011 01100001 01100011 01100001
Waste of resources.
Upgrade to Unicode: utf-8.
utf-8: Use at least 8 digits to represent a character.
a:01100001 (The letter is represented by 1 byte.)
European text: 01100001 01100001 (Europe is represented by 2 bytes.)
Asian script - Medium: 01100001 01100001 01100001 (Europe is represented by 3 bytes.)
utf-16: use at least 16 digits to represent a character
gbk: National standard.
a : 01100001
Medium: 01100001 01100001
8 bits 1 byte
1024bytes 1kb
1024kb 1MB
1024MB 1GB
1024GB 1TB
formatted output
# name = input('Please enter a name:')
# age = input('Please enter age:')
# sex = input('Please enter gender:')
#
# msg = 'My name is' + name + 'My age is' + age + 'My gender is' + sex
# print(msg)
msg = '''
------------ info of Alex Li -----------
Name : Alex Li
Age : 22
job : Teacher
Hobbie: girl
------------- end -----------------
'''
# formatted output % placeholder sd
# name = input('Please enter your name:')
# age = int(input('Please enter age:'))
# job = input('Please enter the job:')
# hobby=input('Please enter hobby:')
#
# msg = '''
# ------------ info of %s -----------
# Name : %s
# Age : %d
# job : %s
# Hobbie: %s
# ------------- end -----------------
# ''' % (name, name, age, job, hobby)
# print(msg)
#Second way to use
# dec = {
# 'name': 'Old Boy',
# 'age':58,
# 'job':'boss',
# 'hobby':'money',
# }
# msg = '''
# ------------ info of %(name)s -----------
# Name : %(name)s
# Age : %(age)d
# job : %(job)s
# Hobbie: %(hobby)s
# ------------- end -----------------
# ''' % Dec
# print(msg)
# Formatted output. In formatted output, simple % needs to be represented by %%.
# msg = 'My name is %s, this year %s, the learning progress is 2%%' % ('Shuangmeier','18')
# print(msg)
#while else When the while loop is interrupted by break, the else program is not executed.
# count = 0
# while count <= 5:
# count += 1
# print("Loop",count)
# if count == 4: break
#
# else:
# print("The loop is executed normally")
# print("-----out of while loop ------")
operator
# print(2 > 1 and 3 < 4 or 8 < 10 and 4 > 5)
# In the first case, the logical operator is preceded by a comparison operation
# Priority concept: () > not > and > or, the same priority is calculated from left to right.
# print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T
# print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F
# print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
# In the second case, there are numbers before and after the logical operator
'''
x or y if x True,return x,else y
'''
# print(3 or 5)
# print(2 or 5)
# print(0 or 5)
# print(-4 or 5)
# print(3 and 5)
# print(1 or 3 or 4 or 0)
# print(1 or 3 or 0)
# print(1 > 2 and 3 or 4)
'''
Number to bool value conversion
int ---> bool non-zero True, zero False
bool---> int True 1, False 0,
'''
# print(bool(100))
# print(bool(0))