Analyzing then determine primary Python 5 (c)

First, review

Branch : completion of the test and is called the branch judgment based on the results.

Block : the line or lines of code together

Indent : a line of code a little bit to the right

Relational operator (comparison operator) : ==,>,> =, <, <=, =,!

Logical operators : and

 

Second, a plurality of test conditions

1, or

If you use or, as long as any of the conditions is true, it will execute the code.

the INPUT = Color ( " Please enter your favorite color: " )
 IF Color == " Red "  or Color == " Blue "  or Color == " Green " :
     Print ( " You can play this game " )
 the else :
     Print ( " I'm sorry, you can not play this game " )

image

 

Exercise:

1, write a program, the selection of the school basketball players, requires 8-11 years of age to participate in the system from the user input aged age, to judge the system based on age, can participate print out: "You can participate in the basketball team" can not participate print out : "I'm sorry, you can not participate in the basketball team."

2, write a program, the selection of the school basketball player, Grade 2 to Grade 5 required to participate, to judge from the user input system grades grade, systems based on grades, can participate print out: "You can participate in the basketball team," not to participate in print out: "I'm sorry, you can not participate in the basketball team."

3, write a program, school selection of basketball players, requiring age is 8-11 years old or grades were grade 2-5, age, age user input from the system, grade grade, the system judges can participate print out: "You can participate basketball team "can not participate prints out:" I'm sorry, you can not participate in the basketball team. "

Guess you like

Origin www.cnblogs.com/luhouxiang/p/11407767.html