The reason why computers can do many automated tasks is that they can make their own conditions.
For example, enter the user's age and print different contents according to age. In a Python program, you can use if statements to implement it:
age = 20 if age >= 18: print 'your age is', age print 'adult' print 'END'
Note: ==Indentation rules for Python code==. Code with the same indentation is considered a code block, and the above 3 and 4 lines print statements form a code block (but not the print on line 5). If the if statement determines to be True, this code block will be executed.
Please strictly follow Python's customary writing method: == 4 spaces ==, do not use Tab, and do not mix Tab and spaces, otherwise it will easily cause syntax errors caused by indentation.
Note: The if statement is followed by an expression, and then use: to indicate the code block to start.
If you type code in a Python interactive environment, you should pay special attention to indentation, and exiting indentation requires one more line to press Enter:
>>> age = 20 >>> if age >= 18: ... print 'your age is', age ... print 'adult' ... your age is 20 adult
Task
If the score reaches 60 or above, it is considered passed.
Assuming that Bart's score is 75, please use the if statement to determine whether it can be printed out. Passed:
Answer:
score = 75 if score >= 60: print 'passed'