[Python] basic knowledge exercise question 1, python exercise question

Source: Internet
Author: User

[Python] basic knowledge exercise question 1, python exercise question
1. Two ways to execute Python scripts

1. python zhurui. py
2. Brief the relationship between bit and byte
8-bit one byte
3. Briefly describe the relationship between ascii, unicode, utf-­ ‐8, and gbk. 4. Write down the digits occupied by utf-­ ‐8 and gbk encoding respectively.
A Chinese Character UTF-8 occupies 3 bytes, and UTF-8: 6 gbk: 4
5. What are the use of Pyhton single-line and multi-line annotations? 6. What are precautions for declaring variables? 7. If the variable n1 = 5 is available, use the method provided by int to obtain how many binary bits can be used to represent the variable size? 8. What are the Boolean values? 9. Read the code and write the execution result.
a = "zhurui"b = a.capitalize()print(a)print(b)
10. write code with the following variables. implement each function as required.

Name = "zhuRui"

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 of 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" in the value corresponding to the name variable with "p" and output the result.

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

F. What type of value is obtained after dividing e in the previous question (optional )?

G. Change the value of the name variable to uppercase and output the result.

H. Write down the value corresponding to the name variable and output the result.

I. Can I output the 2nd characters of the value corresponding to the name variable?

J. Can I output the first three characters of the value corresponding to the name variable?
K. Please output the last two characters of the value corresponding to the name variable?

L. output the index location of "e" in the value corresponding to the name variable?

M. Obtain the subsequence, which does not contain the last character. For example, oldboy gets oldbo; root gets roo

11. Can a string iterate an object? For example, can I use for loop every element? 12. Use the code to implement it:

A. concatenate each element of the list into a string using an underline, li = "alexericrain"

B. concatenate each element of the list into a string using an underline. li = ['Alex ', 'Eric', 'rain'] (optional)

v = "_".join("dsgewrerwewerwe")v = '"_".join(['zhurui','zhurui1'])        "zhurui_zhurui1"
13. What is the difference between range in Python2 and range in Python3?

Python2: directly create

Range: Create now

Xrange: equivalent to the range in python3, Which is discarded in python3.

Python3: After the range is executed, it is first put into the memory and will be created one by one only when the for loop iteration is executed; if the for loop is not executed, it will never be created;

14. Implement an integer addition calculator:

For example:

Content = input ('enter content :')

# Example: 5 + 9 or 5 + 9 or 5 + 9

Input: string "5 + 9" value = "5 + 9" v1, v2 = value. split ('+') v1 = int (v1) v2 = int (v2) v1 + v2

15. How many decimal places does the input content contain? How many letters?

For example:

Content = input ('Enter the content: ') # example: asduiaf878123jkjsfd-‐213928

C1 = 0c2 = 0val = input ('>>>>') for item in val: # if the item is a number: c1 + = 1 # if the item is a letter: c2 + = 1

 

16. Briefly describe the relationship between numbers such as int and 9 and strings such as str and "xxoo?

Int: 7 8 9

Str: zhurui

Bool: True False

Conclusion: int, str, and bool are equivalent to classes, while the values after the colon are equivalent to objects. They are the relationships between classes and objects;

17. Create a fun template program

Requirement: Wait for the user to enter the name, location, and hobby to make any reality based on the user's name and hobby

For example: Dear and amiable xxx, you like to work in xxx

 

Template = "adgegeewrerweew {0}., ggerewgw {1 }"

Name = input (">>>>>> ")

V = template. format ("zhurui", 18)

 

18. Create a Random verification code, which is case insensitive.

Process:

-─‐User execution Program

--Display the verification code to be entered to the user

-─‐User input value

The value entered by the user and the displayed value are both correct and realistic; otherwise, the random verification code is generated and the user enters the verification code.

Sample Code for generating a Random verification code:

while True:       code = check_code()        print(code)        v = input(">>>>>")

 


19. Develop a sensitive word filter program and prompt the user to enter the content. If the content entered by the user contains special characters:

For example, "instructor Cang" "", replace the content ***

 

V = "erewewrew"

V = v. replase ('s ', "rewerwer ")

V = v. replase ('A', "rewerwer ")

Print (v)

Measure the test taker's knowledge about the replacement method of string replase;

20. Create a table

Cyclically Prompt user input: User Name, password, and email address (the length of user input must not exceed 20 characters. If the length is exceeded, only the first 20 characters are valid)

If the user inputs q or Q, the user does not input any more, and the content entered by the user is in the form of a table.

Expandtabs

Len

[0: 20]

s = ""while True:     v1 = input(">>>")     v2 = input(">>>")     v3 = input(">>>")     template = "{0}\t{1}\t{2}\n{0}\t{1}\t{2}\n{0}\t{1}\t{2}\n"     v = template.format(v1,v2,v3)             s  = s + v     breakprint(s.expandtabs(20))

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.