python[Little Turtle 008 Great branches and Loops 2]

Source: Internet
Author: User

Case: Rating the given score, the following are three options:

score = Int (input (' Please enter a fraction '))              #第一种方案if >= score >=:        print (' A ') if > score >=:        print (' B If > Score >=:        print (' C ') if 0 > Score >=:        print (' D ') Else:        print (' Input error! ‘)

  

score = Int (input (' Please enter a fraction '))              #第二种方案if >= score >=:        print (' A ') Else:        if > Score >= 80:
   print (' B ')                else:                        if > Score >=:                                print (' C ')                        else: if-                                > Score >= 0:                                        Print (' D ')                                                else:                                                        print (' Input error! ‘)

  


score = Int (input (' Please enter a fraction '))              #第三种方案if >= score >=:        print (' A ') elif > Score >=:        print ( ' B ') elif > Score >=: Print (        ' C ') elif > score >= 0:        print (' D ') Else:        print (' Input error! ‘)

  




Of the above three scenarios, the third one has the lowest time complexity.



#注意 Hang Else

For example, a beginner in C can easily be fooled by a bit of code.

if (Hi > 2)    if (Hi > 7)        printf (' good ') Else    printf (' Fuck ')

  

    • Conditional expressions (Ternary operators)


syntax: x if condition else y


    • Assertion (Assert)

Assert this keyword we call assertions, when the condition behind this keyword is false when the program automatically crashes, throwing Assertionerror exceptions.


As An example ,

Assert 3 > 4

  

This statement is often used to set a checkpoint in a program, which is used to debug a program.


python[Little Turtle 008 Great branches and Loops 2]

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.