day1-python basics

As shown in the picture is the syllabus of the first day. The left side is to understand the part, and the right side needs to be mastered and practiced more (hands).

Exercise questions:

  1. Enter 1 2 3 4 5 6 8 9 10 using a while loop
    1 count=1
    2 while count<11:
    3     print(count)
    4     if count ==6:
    5         count +=1
    6         print(" ")
    7     count +=1
    8     
    loop output
  2. Find the sum of all numbers from 1 to 100
    1 count = 1
    2 sum = 0
    3 while count<101:
    4     sum= sum + count
    5     count= count + 1
    6 print(sum)    
    Sum of all numbers from 1 to 100
  3. print all odd numbers from 1-100
    1 count=1
    2 while count<101:
    3     
    4     print(count)
    5     count +=2
    Output all odd numbers 1-100
  4. print all even numbers from 1-100
    1 count=0
    2 while count<101:
    3     
    4     print(count)
    5     count +=2
    print all even numbers from 1-100
  5. Find the sum of all numbers 1-2+3-4+5 ... 99
    1 sum=0
    2 i=0
    3 while i<100:
    4     if i%2==0:
    5         sum -=i
    6     else:
    7         sum +=i
    8     i +=1
    9 print(sum)
    Find the sum of all numbers 1-2+3-4+5 ... 99
  6. User login (three chances to retry)
    1 t= 0
     2  while t<3 :
     3      show=input( " Please start your show! " )
     4      dream=input( " What are your dreams? " )
     5      if show == " poping " :
     6          if dream= = " dancer " :
     7              print ( " Give the towel and win the championship together " )
     8              break  
    9          else :
     10              print ( " Your dream is a little floating " )
    11          t +=1
     12      else :
     13          print ( " Sorry, you are not good enough " )
     14          t +=1
     15      if t==3 :
     16          print ( " Battle three times, sorry! " )
     17     
    User login (three chances to retry)

Guess you like

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