python 分支

发布时间:2019-09-08 09:11:38编辑:auto阅读(1875)

    ##

    ##def functiontest():

    ##    x=int(raw_input('please input number:'));

    ##    if(x>8):

    ##        print "larger than 8";

    ##    else:

    ##        print "lower than 8";

    ##functiontest();

    ##

    ##def functionSex():

    ##    sex=str(raw_input('please input number:'));

    ##    if(sex=="male"):

    ##        print "male";

    ##    else:

    ##        print "lady";

    ##

    ##functionSex();

    ###if else multi 嵌套对齐

    ##def grade():

    ##    x=int(raw_input("print you grade:"));

    ##    print x;

    ##    if(x>=90):

    ##        print "A";

    ##    else:

    ##        if(x>=80):

    ##           print "B";

    ##        else:

    ##           if(x>=70):

    ##            print "C";

    ##           else:

    ##              if(x>=60):

    ##                print "D";

    ##              else:

    ##                 print "E";

    ##

    ##grade()

    #对齐 if 条件表达式非0就真

    def multigrade():

       x=int(raw_input("print you grade:"));

       print x;

       if(x>=90):

           print "A";

       elif(x>=80):

          print "B";

       elif(x>=70):

         print "C";

       elif(x>=60):

         print "D";

       else:

        print "E";


    multigrade();


    #条件的判断 逻辑表达式:双目运算/单目运算++

    #-and or not

    sex=raw_input("input sex:");

    if (sex=='M' or sex=='m' or sex=='man'):

       print 'man';

    if sex!='woman':

       print 'haha';



关键字