Unit 3: Boolean Expressions, if statements - Python Tutorial
Unit 3: Boolean Expressions, if statements
if-else if-else statements
Adapted from:
1) Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp 2) Runestone CSAwesome Curriculum
Type boolean
? boolean: A logical type whose values are true and false.
? It is legal to:
? create a boolean variable ? pass a boolean value as a parameter ? return a boolean value from methods ? call a method that returns a boolean and use it as a test
int age = 22; boolean minor = age < 21; // false boolean lovesAPCS = true; boolean is1049Prime = isPrime(1049);
2
Relational expressions
? Tests use relational operators:
Operator
==
!=
< > =
equals
Meaning
does not equal
less than greater than less than or equal to
greater than or equal to
Example
Value
1 + 1 == 2 true
3.2 != 2.5 true
10 < 5 false 10 > 5 true 126 = 5.0 true
3
Relational Expressions
public class Boolean_Class{ public static void main(String[] args){ int x = 2, y = 3; System.out.println(x == y); // false System.out.println(x != y); // true System.out.println(2 + 4 * 3 5); // false System.out.println(y >= 3); // true
} }
4
The if statement
Executes a block of statements only if a test is true
if (test) { statement; ... statement;
} statement;
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- python conditional statements
- computer science 1000 part 7 programming in python p l
- unit 3 boolean expressions if statements python tutorial
- programming for gcse topic 3 1 if statements in python
- python if else rxjs ggplot2 python data persistence
- conditional and iterative statements
- conditional statements in python
- python selection if else basic selection statement
- python iterative statements
Related searches
- multiple if statements in tableau
- if statements verilog
- how to write multiple if statements excel
- nested if statements in excel with dates
- embedded if statements in excel
- multiple if statements with dates
- multiple if statements in excel
- excel if statements with dates
- if statements using dates
- if statements with range of numbers
- if statements using dates in excel
- using if statements with dates in excel