Python Little Exercise

Source: Internet
Author: User

1.

#使用while循环输出1 2 3 4 5 6     8 9 10count=1while count < one:    if Count = = 7:        count+=1        continue    print (count )    Count+=1

2.

All odd for J in range (1,100) within #输出 1-100:    if j%2==0:        continue    print (j)

3.

All even for I in range (1,51) #输出 1-100:    i+=i    Print (i)

4.

#求1 -2+3-4+5 ... 99 of all numbers and j = 1o = 0while j<=99:    if j%2==0:        o-=j    Else:        o+=j    j+=1print (o)

5.

#用户登陆 (three chance retry n = 0while n<3:    user=input (' Please enter your name: ')    password=input (' passwd: ')    if user = = ' Buer ' and Password = = ' 1234.com ':        print (' login successful! ')        While True:            shu = input (' >>>: ')            if Shu = = ' quit ':                n=3 break    Else:        print (' Login Fail ')        n+=1

6.

#输入quit退出循环while True:    sentence=input (' Please enter content: ')    if sentence = = ' quit ': Break    Else:        print ( Sentence)

7.

#求1 100 Add sum = 0for x in range (101):    sum+=xprint (SUM)

8.

#输入名字name = input (' Please your Name: ') print (' Hello, ', name)

9.

#求奇数和偶数的和j = 0o = 0while j<=100:    if j%2==0:        o+=j    Else:        o+=j    #print (j)    J+=2print (' Even sum: ', O ) j = 1o = 0while j<=100:    if j%2==0:        o-=j    Else:        o+=j    #print (j)    j+=2print (' odd sum: ', O)

10.

#登录用户buer, password 123, enter the user input quit the Loop tag=truewhile tag:    name=input (' Please your Name: ')    pswd=input (' Please your Password: '    if name = = ' Buer ' and pswd = = ' 123 ':        print (' login successful! ')        While tag:            cmd=input (' ==>>: ')            if cmd = = ' quit ':                tag=false                continue            print (cmd)

11.

#乘法口诀表for i in range (1,10):    to J in Range (1,i+1):        print ('%s*%s=%s '% (i,j,i*j), end= ')    print ()

12.

# Write A For loop, using an index to traverse out each character msg = ' Hello Egon 666 ' for X in range (len (msg)):    print (msg[x], end= ")

13.

# Write a while loop, using an index to traverse out every character msg = ' Hello Egon 666 ' Count = 0 while count < Len (msg):     print (Msg[count])     count + = 1

14.

# msg= ' Hello Alex ' in Alex replaced with SB msg= ' Hello Alex ' Print (Msg.replace (' Alex ', ' SB '))

15.

# msg= '/etc/a.txt|365|get ' to cut the character's file name, file size, operation method msg= '/etc/a.txt|365|get ' Print (Msg.split (' | '))

16.

# Write a while loop that requires the user to enter a command, and if the command is empty, continue to enter while True:     user=input (' Please enter directive: ')     if user== ':         continue     Else: Break         

17.

# 6. Write a while loop, let the user enter a user name and password, if the user is empty or number, re-enter while True:     name=input (' Please enter your name: ')     passwd=input (' Please your password: ')     if name== ' or Name.isdigit ():            #isdigit () string is an integer         print (' username cannot be empty or number ')         Continue     else:         break

18.

# 7. Write the while loop, let the user enter the content, and judge what the input begins with Alex, add the string _SB to the end while True: #第一种方法     con=input (' Please input: ')     aa= ' al Ex '     if Con[:4]==aa[:4]:               #[:4] Slice, from the beginning 4-bit string slice         print (con, ' _sb ') while True: #第二种方法     MSG=INP UT (' Please enter content: ')     if Msg.startswith (' Alex '):            #startswith () with what character or string starts with         print (msg, ' _SB ')

19.

# 8.1. Two-layer while loop, the outer while loop, let the user enter a user name, password, work for several months, the monthly salary (integer), the user name or password is empty, or the number of months of work is not an integer, or # Month salary is not an integer, then re-enter tag = truewhile tag: user = input (' User name: ') passwd = input (' Password: ') work_mons = input (' month: ') salary = input (' Payroll: ') if work_mons.isdigit () and Salary.isdigit (): # IsDigit () determines whether an integer work_mons = int (work_mons) salary = Int (salary) # if use r== "or passwd==" or not isinstance (work_mons,int) or not isinstance (salary,int): # print (' malformed ') if user! = ' ' and passwd! = ' and isinstance (work_mons, int) and isinstance (salary, int): print ('-------------------Login succeeded------        -----------') print ('-------Welcome to the background query system version:1.0-------') print ('----------------1. Query total Salary----------------') Print ('---------------2. Query user Identity---------------') print ('-----------------3. Sign out-----------------') pri NT () print () while tag:cmd = input (' ===>>: ') if cmd = = ' 1 ': prin T (' Total Salary: ', work_mons * salary) elif cmd = = ' 2 ': if user = = ' Alex ': Print (' Super suer ') elif user = = ' Yuanhao ' or user = = ' Wupeiqi ': print (' normal user ') Else:p    Rint (' unkown user ') elif cmd = = ' 3 ': Tag = False else:print (' input error ') Else:print (' format error ') continue

Python Little Exercise

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.