Basic Exercise 1

1. Two ways to execute Python scripts

 

2. Briefly describe the relationship between bits and bytes

 8 bits equals one byte

3. Briefly describe the relationship between ascii, unicode, utf-‐8, gbk

 

4. Please write the number of bits occupied by "Li Jie" encoded with utf-8 and gbk respectively

 

5. What are Python single-line comments and multi-line comments used for?

 Single line:

Multiple lines: ctrl+?

6. What are the precautions for declaring variables?

 

7. If there is a variable n1 = 5, please use the method provided by int to get the minimum number of binary bits that the variable can be represented by?

n1 = "5"
v = int(n1)
print(v)

 

 

 

8. What are Boolean values?

 

9. Read the code, please write the execution result

a = "alex"

b= a .capitalize()

print(a) print(b)

Please write the output: "alex" "Alex"

 

10. Write code, there are the following variables, please implement each function as required

name = " aleX"

a. Remove the spaces on both sides of the value corresponding to the name variable, and enter the removed content

b. Determine whether the value corresponding to the name variable starts with "al", and output the result

c. Determine whether the value corresponding to the name variable ends with "X", and output the result

d. Replace "l" with "p" in the value corresponding to the name variable, and output the result

e. Divide the value corresponding to the name variable according to "l", and output the result.

 

f. Excuse me, what type of value is obtained after dividing e in the previous question (optional)?

g. Capitalize the value corresponding to the name variable and output the result

h. Lowercase the value corresponding to the name variable and output the result

i. Please output the second character of the value corresponding to the name variable?

j. Please output the first 3 characters of the value corresponding to the name variable

k. Please output the last 2 characters of the value corresponding to the name variable?

l. Please output the index position of "e" in the value corresponding to the name variable?

m. Get the subsequence, only excluding the last character. For example: oldboy gets oldbo; root gets roo

 

21. Is a string an iterable object? If possible please use a for loop for each element?

 

 

 

22. Please use code to implement:

 

 

a. Use the underscore to concatenate each element of the list into a string, li = b. Use the underscore to concatenate each element of the list into a string, li =


 

 

"alexericrain" ['alex', 'eric', 'rain']


 

 

(optional)

 

 

 

23. What is the difference between range in Python2 and range in Python3?

 

24. Implement an integer addition calculator:

 

Such as:

 

 

content = input('Please input content:') # Such as: 5+9 or


 

 

5+ 9


 

 

or 5 + 9

 

 

 

25. Calculate how many decimal fractions are there in the content entered by the user? How many letters?

 

Such as:

 

content = input('Please enter the content:') # Such as: asduiaf878123jkjsfd-‐213928 26. Briefly describe the relationship between numbers such as int and 9, and strings such as str and "xxoo"?

 

 

27. Make fun template programs

 

Requirement: Wait for the user to input name, location, hobby, and perform arbitrary reality according to the user's name and hobby

 

Such as: Dear xxx, I like to do xxx in xxx place the most

 

28. Make a random verification code, which is not case-sensitive.

 

process:

 

- User executes the program

 

- Show the user the verification code that needs to be entered

 

- the value entered by the user

 

When the value entered by the user is the same as the displayed value, the correct information is displayed; otherwise, the random verification code continues to be generated and the user continues to wait for the input to generate the random verification code. Code example:

 

 

 

29. Develop a filter program for sensitive words, prompting the user to input content, if the content input by the user contains special characters:

 

For example, "Teacher Cang" and "Tokyo Hot", replace the content with ***

 

 

 

30. Make a table

 

Prompt the user to input in a loop: user name, password, email address (the length of the user input is not more than 20 characters, if it exceeds, only the first 20 characters are valid) If the user enters q or Q, it means no more input, and the content entered by the user is changed. Hidden in tabular form

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325257805&siteId=291194637