"22" Python Basic Learning Note 1

Source: Internet
Author: User
Tags python script

Practice Questions:
1. Describe the differences between compiled and interpreted languages, and list which languages you know are compiled and which are interpreted
Compiled language: Like a textbook, no matter which knowledge point, the compiler language first is to first the whole book involved in the knowledge points are explained once. For example, enter a series of commands, the standard input, and then according to the compilation environment to find the translated content, to the computer, the last CPU processing
Interpreted language: Which section do you need, I explain to you which paragraph, not the whole book translation, more flexible, but inefficient. After standard input, you need to PYC cache one, then go into the virtual machine, convert to machine recognition language, and finally CPU executes
2. What are the two ways to execute a Python script
Python hello.py
#! /usr/bin/env python: Uncertain interpreter-specific path
#! /usr/bin/python: You can use this method when you know the path to the interpreter installation.
what are 3.Pyhton single-line comments and multiline comments used separately?
Single-line comment: Pound sign
Multiline Comment: Multi-quote
4. What are the Boolean values?
True&false
5. What are the considerations for declaring variables?
Keyword.kwlist
Variable names cannot have spaces and can be connected with underscores
Best First Letter Capitalization
Constants are capitalized on variable names
Do not start with a number

6. How do I see the address of a variable in memory? (Baidu found, is to understand the non-understand, I make a variable to see the variable memory address, the result I do not post)

name="Alex"print(id(name).__doc__)

7. Write code i. Implement user input user name and password, when the user name is seven and the password is 123, the display login is successful, otherwise the login failed!

u=["zhang",123]username=input("Input name:")password=int(input("Input password:"))if username == u[0] and password == u[1]:    print("login success!")else:    print("false")
u=["zhang","123"]def login(x,y):    if x == u[0] and y==u[1]:        print("success")    else:        print("false")login(x=input("user:"),y=input("pass"))

II. Implement user input user name and password, when the user name is seven and the password is 123, the display login is successful, otherwise the login failed, the failure to allow repeated input three times

u=["zh","123"]count=0while count <3:    user_name=input("input username>>> ")    pass_word=input("input password>>> ")    if user_name==u[0] and pass_word ==u[1]:        print("success!")        break    else:        print("false")    count +=1

III. Implement user input user name and password, when the user name is seven or Alex and the password is 123, the display login is successful, otherwise the login failed, the failure to allow repeated input three times

count=0user_info="zh:123#ch:123"user_list=user_info.split("#")user_dict={}for i in user_list:    item=i.split(":")    user_dict[item[0]]=item[-1]username=input("input user>>> ")if username in user_dict:    while count < 3:        password = input("input pass>>> ")        if password == user_dict[username]:            print("sueccess")            exit()        else:            print("密码错误")        count += 1else:    print("user error")

8. Write code
A. Using a while loop to implement output 2-3+4-5+6...+100 and
My idea is: add and subtract odd numbers with even numbers and

count=2l=[]a=[]while count <=100:    if count%2 ==0:        a.append(count)    else:        l.append(count)    count +=1print(sum(l))print(sum(a))print(sum(a)-sum(l))

B. Using a while loop to implement output 1,2,3,4,5, 7,8,9, 11,12 D.

count =1l=[]while count<=12:    if count !=6 and count !=10:        l.append(count)    count +=1print(l)

D. Using a while loop to implement all odd numbers in output 1-100

count=0l=[]while count <100:    if count%2 !=0:        l.append(count)    count +=1print(l)

E. Using a while loop to implement all the even numbers in output 1-100

count=0l=[]while count<=100:    if count%2==0:        l.append(count)        print(sum(l))    count +=1print(l)

9. The following two variables are available, please briefly describe what is the relationship between N1 and N2?
N1 = 123456
N2 = N1

A: N2 is a n1 dependent variable that changes as the N1 changes

10. Create Fun template programs (programming questions)
Requirements: Wait for the user to enter a name, place, hobby, according to the user's name and hobby to display any
Such as: Beloved lovely xxx, favorite in XXX place dry xxx

def mode():    name=input("what‘s your name>>>")    address=input("home add>>>")    job=input("input job>>>")    print(‘‘‘    ------------%s的个人信息-----------    name    :%s    address :%s    job     :%s    ‘‘‘%(name,name,address,job))if __name__==‘__main__‘:    mode()

11. Enter a year to determine whether the year is a leap years and output the results. (Programming Questions)
Note: A year in which one of the following two conditions is met is a leap years. (1) can be divisible by 4 but not divisible by 100. (2) can be divisible by 400.

year=int(input("input year>>> "))if year%4 ==0:    print("%s年是闰年"%year)else:    print("不是闰年")def year(n):    if n%4==0:        print("闰年")    else:        print("No")if __name__ == "__main__":    year(n=int(input("input year>>>")))

12. Assuming that the one-year periodic interest rate is 3.25%, to calculate the need for an excessive number of young, 10,000 yuan of one-year time deposit to double the band? (Programming Questions)
It is assumed that a year is calculated once, the result is 22 years even this band double, if fixed 10,000 yuan unchanged, need 30 years double.

count=0n=0.0325l=[]while True:    if count >1:        print(count)        print(len(l))        break    else:        count += n*(count+1)        l.append(count)

"22" Python Basic Learning Note 1

Related Article

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.