Top Posters
Since Sunday
n
6
t
5
k
4
j
4
d
4
d
4
t
4
a
4
d
4
m
4
d
4
p
4
A free membership is required to access uploaded content. Login or Register.

Lab 3 Python Instructor Manual

Uploaded: 7 years ago
Contributor: Guest
Category: Computer Science
Type: Lecture Notes
Rating: N/A
Helpful
Unhelpful
Filename:   Lab 3 Python Instructor Manual.doc (42 kB)
Page Count: 2
Credit Cost: 1
Views: 152
Last Download: N/A
Description
Lab 3 Instructors Manual
Starting Out with Programming Logic and Design, 3rd Edition
Transcript
Python Instructor Manual 2 Python Instructor Manual Lab 3: Decisions and Boolean Logic Relational Operators Relational operators used in Python are as follows: Operator Meaning > Greater than < Less than >= Greater than or equal to <= Less than or equal to == Equal to != Not equal to The >= and <= Operators Two of the operators, >= and <=, test for more than one relationship. The >= operator determines whether the operand on its left is greater than or equal to the operand on its right. The <= operator determines whether the operand on its left is less than or equal to the operand on its right. The == Operator The == operator determines whether the operand on its left is equal to the operand on its right. If the values referenced by both operands are the same, the expression is true. The != Operator The != operator is the not equal to operator. It determines whether the operand on its left is not equal to the operand on its right, which is the opposite of the == operator. The if Statement In Python we use the if statement to write a single alternative decision structure. Here is the general format of the if statement: if condition: statement statement etc. For simplicity, we will refer to the first line as the if clause. The if clause begins with the word if, followed by a condition, which is an expression that will be evaluated as either true or false. A colon appears after the condition. Beginning at the next line is a block of statements. (Recall from Chapter 3 that all of the statements in a block must be consistently indented. This indentation is required because the Python interpreter uses it to tell where the block begins and ends.) When the if statement executes, the condition is tested. If the condition is true, the statements that appear in the block following the if clause are executed. If the condition is false, the statements in the block are skipped. Comparing Strings Python allows you to compare strings. Remind students that strings are entered with the raw_input function such as: birthMonth = raw_input(‘Enter your guess for birth month:’) Python allows you to compare strings. Remind students that strings are case sensitive so when entering test values, if the month is compared to April, the A must be capital. For example: if birthMonth == 'April': print 'Congratulations, the birth month is April.'

Related Downloads
Explore
Post your homework questions and get free online help from our incredible volunteers
  1565 People Browsing
Your Opinion
Who's your favorite biologist?
Votes: 608