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: at the same time is true
or: any one is true
Second, a plurality of test conditions
1, not
Denotes the inverse logic, not used
int = Age (the INPUT ( " Please enter your age: " )) IF not (Age <8 ): Print ( " you can join basketball team " ) the else : Print ( " I'm sorry, you can not participate in the basketball team ." )
Not removing said:
int = Age (the INPUT ( " Please enter your age: " )) IF Age> = 8 : Print ( " you can join basketball team " ) the else : Print ( " I'm sorry, you can not participate in the basketball team ." )
Exercise:
1, input age, age, senior grade, if older than 8 and equal to Grade 3 or greater, you can output the basketball team, otherwise output'm sorry, you can not participate in the basketball team
Age = int (the INPUT ( " Please enter your age: " )) Grade = int (the INPUT ( " Please enter your grade: " )) IF Age> = 8 and Grade> = 3 : Print ( " you can participate in basketball the team " ) the else : Print ( " I'm sorry, you can not participate in the basketball team . " )
How will this judgment into a test of containing or:
Age = int (the INPUT ( " Please enter your age: " )) Grade = int (the INPUT ( " Please enter your grade: " )) IF not (Age> = 8) or not (Grade> = 3 ): Print ( " I'm sorry, you can not participate in the basketball team " ) the else : Print ( " you can join the basketball team ." )
2. Enter the color you like color, if you like blue or blue-green, output You can play this game, otherwise the output I'm sorry, you can not play this game
the INPUT = Color ( " Please enter your favorite color: " ) IF Color == " Blue " or Color == " Green " : Print ( " You can play this game " ) the else : Print ( " I'm sorry, you can not play this game . " )
Will convert it to contain and test
the INPUT = Color ( " Please enter your favorite color: " ) IF not (Color == " Blue " ) and not (Color == " Green " ): Print ( " I'm sorry, you can not play this game " ) the else : Print ( " you can play this game ." )
3. Enter your age age, grade and grades favorite color, if older than 8 and equal to Grade 3 or greater, while like blue or green, you can participate in the output basketball game, otherwise you can not participate in the basketball game output
Age = int (the INPUT ( " Please enter your age: " )) Grade = int (the INPUT ( " Please enter your grade: " )) Color = the INPUT ( " Please enter your favorite color: " ) IF Age> = 8 and Grade> = 3 and (== Color " Blue " or Color == " Green " ): Print ( " you can join the basketball team game " ) the else : Print ( " I'm sorry, you can not participate in the race basket " )
Homework:
1, a mall promotion in reduced order. If the amount is less than or equal to the purchase price of 100 yuan, will give a 10% discount, if the purchase amount is greater than $ 100, will give a 20% discount. Write a program that asks the purchase price, and then show discount (10% or 20%) and the final price
AMOUNT = float (the INPUT ( " Please enter the amount: " )) IF AMOUNT <= 100 : Print ( " discount: 10%, the amount due: " , AMOUNT * (1 - 0.1 )) the else : Print ( " discount: 20%, the amount shall be: " , aMOUNT * (1 - 0.2))
2, a women's soccer team looking for younger girls between 10-12 years of age to join. Write a program that asks the user's age and gender (male or female), if the person between the ages of 10-12 years old, and a girl, the output can participate in football, otherwise the output I'm sorry, you can not participate in the football team.
int = Age (the INPUT ( " Please enter your age: " )) Sex = int (the INPUT ( " Please enter your gender: " )) IF Age> = 10 and Age <= 12 and Sex == " female " : Print ( " you can participate in soccer team " ) the else : Print ( " you can not participate in the football team " )
3, the previous question, the rational optimization, if the user is not the age of the girls do not have to ask
the INPUT = Sex ( " Please enter your gender: " ) IF not Sex == " female " : Print ( " I'm sorry, you are not a girl, not to participate in women's soccer team " ) the else : Age = int (the INPUT ( " Please enter your age: " )) IF Age> = 10 and Age <= 12 : Print ( " you can participate in the women's soccer team " ) the else : Print ( " I'm sorry, you can not participate in the women's soccer team . " )