Preliminary Getting Started Exercises

n= 0
 while n<= 100 :
     if n% 3 == 0 and n% 5 == 0 :
         print ( n, "is a multiple of 3 and 5" )
     elif n% 5 == 0 :
         print (n, " is a multiple of 5" )
     elif n% 3 == 0 :
         print (n, "is a multiple of 3" )
     elif n% 11 == 0 :
         break
     n=n+ 1
else :
     print ( "End of loop" )
 #
 nums= range ( 5 )
 for i in range ( 35 , 18 ,- 3 ):
     print (i)
 for i in range ( 9 ): a few lines
     for i in range ( 9 ) : several stars in a line
          print ( "*" , end = "" )
     print ()

Ninety-nine multiplication table
for i in range(1,10):
    for j in range(1,i+1):
        print(j,'*',i,'=',(j*i),end='\t')
    print()
isosceles triangle
rows= int ( input ( "Please enter the number of diamond rows:" ))
s=rows//2+1
x=rows-s
for i in range(s):
    for j in range(s-1,i,-1):
        print(' ',end='')
    for k in range(i*2+1):
        print('*',end='')
    print()
for i in range(1,x+1):
    for j in range(i):
        print(" ",end="")
    for k in range((s-i)*2-1):
        print("*",end="")
    print()
loop statement
a=b=c=d=0
while True:
    num= int ( input ( "Please enter grade:" ))
     if num>= 90 and num<= 100 :
        a+=1
elif num>=80 and num<90:    
        b+=1
elif num>=60 and num<80:    
        c+=1
elif num>=0 and num<60:    
        d+= 1
 else :
         print ( "Out of range, please re-type" )
         continue # Put it back to the position where the loop condition is judged must be in the loop body
 str= input ( "Do you want to continue? y/n" )
     if str. __eq__ ( 'n' ):
         break
 print ( '>=90:' ,a)        
count= 0
 for i in range ( 1 , 4 ):
     print ( "Please enter the grades of students in " ,i, "classes:" )
     for j in range ( 1 , 4 ):
        score= int ( input ( "Please enter the first" +str(j)+ "Student grade:" ))
         if score< 0 :
             print ( "Enter a negative number to enter the next class" )
             break
         if score< 80 :
             continue
         count+= 1
 print ( "Number of people greater than 80:" ,count)

Guess you like

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