Python Basics Exercises

Source: Internet
Author: User

    1. 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")             Break
While 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("")             Break
for 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 sibling
if 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

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.