Knight program DAY02

Keywords: Pycharm ascii

01 while loop

while infinite loop
while True:  # Dead cycle
    print('Incantations of the Great Mercy')
    print('Two tigers')
    print('Great prince')
    print('Pick me up please,you skilled driver!')
while Structure of the cycle:
'''
while condition:
    //Circulatory body
'''

# How to terminate a loop?
# 1. Change the condition (the concept of flag bit)
# 2. Break stops the cycle.
# flag = True
# while flag:
#     print('Great mercy curse ')
#     print('two tigers')
#     flag = False
#     print('farewell my concubine ')
#     print('old driver takes me ')

# Exercise 1-100
# 1
# 2
# 3
# ...
# 100
# Method 1:
# flag = True
# count = 1
# while flag:
#     print(count)
#     count = count + 1
#     if count == 101:
#         flag = False

# Method 2:
# count = 1
# while count < 101:
#     print(count)
#     count = count + 1

# In the break loop, as soon as a break is encountered, the loop ends.

# while True:
#     print(111)
#     print(222)
#     break
#     print(333)
#     print(444)
# print(123)

# Using break, while, calculate the result of 1 + 2 + 3.... 100

# count = 1
# sum = 0
# while True:
#     sum = sum + count
#     count = count + 1
#     if count == 101:
#         break
# print(sum)

# Continue: end this cycle and continue the next cycle.

# while True:
#     print(111)
#     print(222)
#     continue
#     print(333)

# while else structure

# If the while loop is broken by break, else code is not executed.
# count = 1
# while count < 5:
#     print(count)
#     count = count + 1
#     if count == 3: break
# else:
#     print(666)
# print(222)

# Application scenario:
#     Verify the user name and password. Re entering this function requires a while loop.
#     Infinite display page, infinite input

02 format output

To make a template, the parameters in some places are dynamic. Like this, you need to format the output.

Dynamic replacement of strings
# -*- coding: utf-8 -*-
# @Time    : 2018/8/3 11:57
# @Author: Knight plan
# @Email   : customer@luffycity.com
# @File: 04 format output.py
# @Software: PyCharm

#
# name = input('Please enter name: ')
# age = int(input('Please enter age: ')
# sex = input('Please enter gender: ')
# %Placeholder s data type is string d number
# The first way:
# msg = 'your name is% s, your age is% d, your gender is% s'% (name, age, sex)
# print(msg)

# The second way
# msg = 'your name is% (name1)s, your age is% (age1)d, your gender is% (sex1) s'% {' name1 ': name,' age1 ': age,' sex1 ': sex}
# print(msg)

# In the format output, if you want to represent only one% of bug points, you should use%%
# msg = 'my name is% s, this year% d, my learning progress is 1%%'% ('off and', 28)
# print(msg)

03 operator

==Whether the values on both sides of the comparison are equal
 =Assignment operation
 ! = not equal to
 +=For example: count = count + 1
-=
*=: count = count * 5 short for count *= 5
/=
**=
//=
. . . . 
Logical operators
and  or  not
    See code for details: operator. py
# -*- coding: utf-8 -*-
# @Time    : 2018/8/3 11:57
# @Author: Knight plan
# @Email   : customer@luffycity.com
# @File: 04 format output.py
# @Software: PyCharm

#
# name = input('Please enter name: ')
# age = int(input('Please enter age: ')
# sex = input('Please enter gender: ')
# %Placeholder s data type is string d number
# The first way:
# msg = 'your name is% s, your age is% d, your gender is% s'% (name, age, sex)
# print(msg)

# The second way
# msg = 'your name is% (name1)s, your age is% (age1)d, your gender is% (sex1) s'% {' name1 ': name,' age1 ': age,' sex1 ': sex}
# print(msg)

# In the format output, if you want to represent only one% of bug points, you should use%%
# msg = 'my name is% s, this year% d, my learning progress is 1%%'% ('off and', 28)
# print(msg)

04 preliminary understanding of coding

Taibai: Chicken Tonight!
Today: 0101 0001
 Evening: 0101 1101
 Eat: 0101 0001
 Chicken: 0111 1100

0101010 1110101 00000  01011
 The above is unreasonable. It should be disconnected,

01010001 01011101 01010001 01111100
 Lu Ke
 A broken position.
There should be a codebook: the correspondence between the recorded plaintext and binary.

ASCII: original version of codebook: all English letters, numbers, special characters.
        First:
            One character 000 0001
            Later optimization
            A: 01000001 8 bits = = 1 byte
            a:  01100001
            c:  01100011
        For ASCII:
            'hello lady' 11 characters, 11 bytes.

unicode: the code of nations. Write all the languages of all countries into this codebook.
    First: 1 character, 16 bits and 2 bytes.
        A: 01000001 01000001
        b: 01000001 01100001
        Middle: 01000001 01100101
    Revision: 1 character, 32 bits, 4 bytes.
        A: 01000001 01000001 01000001 01000001
        b: 01000001 01100001 01000001 01000001
        Of which: 01000001 01100101000001 01000001
        Waste resources, take up space.

utf-8: at least 8 characters.
               A: 01000001 one byte
        Eurotext: 01000001 01100001 two bytes
               Middle: 01000001 01100101000001 three bytes
        'old boy': 9 bytes

gbk: national standard, only including Chinese and English (English letters, numbers, special characters)
    A: 01000001 one byte
    Middle: 01000001 01100101 two bytes


8 bit  == 1bytes
1024bytes == kb
1024kb  ==  1MB
1024MB == 1GB
1024GB == 1TB
1024TB == 1PB
# -*- coding: utf-8 -*-
# @Time    : 2018/8/6 15:30
# @Author: Knight plan
# @Email   : customer@luffycity.com
# @File: 06 for loop.py
# @Software: PyCharm
s1 = 'fkdqe'
# s1[0]
# s1[1]
# s1[2]
# ...
# s1[100]
# print(s1[10])
# index = 0
# while index < len(s1):
#     print(s1[index])
#     index += 1
# If you cycle a data type, or a limited number of times, you often use for
# for i in s1:  # for variable in Iterable (iteratable object: data composed of multiple elements)
#     print(i)
for i in s1:  # The number of for loops is related to the number of elements of the iteration object
    print(666)
Published 8 original articles, won praise 5, visited 2224
Private letter follow

Posted by iamtheironman on Thu, 16 Jan 2020 03:38:19 -0800