- 99 Multiplication Table
i = 0#While 99 multiplication tablej =0 whileI < 9: I+ = 1 whileJ<9: J+ = 1sum= i +J Total="%s +%s =%s"%(i,j,sum)Print(total,end=" ") ifi = =j:j=0Print("\ n") BreakWhile implementation 99 multiplication table
forIinchRange (1,10):#For 99 multiplication table forJinchRange (1,10): Sum= i +J Total= ("%d +%d =%d"%(i,j,sum))Print(total,end=" ") ifi = =J:Print("") Breakfor Implementation 99 multiplication table
2. Performance Judgment
input scores automatically, Judge grade. Demand: 0-59 60-69 pass 70-79 80-89 Liang 90-99 excellent very good-1 Throw Exception 101 Exception
whileTrue:num= str (Input ("pls input num:")) if notNum.isdigit ()orint (num) > 100: Print("Please re-enter") Continue Else: Num=int (num)if0<= Num <= 59: Print("inferior lattice") elif69 <=num<=: Print("Pass") elif79 <=num<=: Print("in") elif80<=num<= 89: Print("Liang") elif<=num<=99: Print("Excellent") elifnum = = 100: Print("very good") Break #Break can also be placed in the else siblingif achieve score judgment
3. Rabbit Calculation
Requirement: 12 months how many rabbits will there be in total?
Rabbit = [All] for in range: + rabbit[i+1 ]) Print (i+1," Moon ", rabbit[i]*2," little Bunny ") Print (Rabbit)
for implementation Bunny calculation
4. Arrange numbers, do not repeat
Requirements: There are four digits 1 2 3 4, respectively, to achieve three numbers matching together, and each number is not duplicated.
forIinchRange (1,5): forJinchRange (1,5): if(i = =j):Continue forKinchRange (1,5): if(j = kori==k):Continue Else: Print("%d%d%d"% (i,j,k))for implementing a digital arrangement
Python Basics Exercises