Download Lecture 4: More Variables Operators and Operands Code Execution ... and more Schemes and Mind Maps Web Programming and Technologies in PDF only on Docsity!
CSCI 141
Lecture 4:
More Variables
Operators and Operands
Code Execution: Statements and Expressions
Announcements
One small syllabus change:
- Previously: drop up to 9 missed poll questions. Now: poll questions are batched by day; drop up to 3 days of missed polls.
Announcements
QOTD
What does the following code print? print ( int (3.91))
Which of the following programs does not print the same thing as the others? a = 14 b = 3 print (a, b) a = 3 b = 14 print ( 14 , 3 ) a = 14 b = a print (a, b) a = 3 b = 14 print ( 14 , a)
A: B:
C: D:
QOTD
Which of the following programs does not print the same thing as the others? a = 14 b = 3 print (a, b) a = 3 b = 14 print ( 14 , 3 ) a = 14 b = a print (a, b) a = 3 b = 14 print ( 14 , a)
A: B:
C: D:
QOTD
Which of the following programs does not print the same thing as the others? a = 14 b = 3 print (a, b) a = 3 b = 14 print ( 14 , 3 ) a = 14 b = a print (a, b) a = 3 b = 14 print ( 14 , a)
A: B:
C: D:
QOTD
Goals
- Understand how to use variables in assignment statements and elsewhere in place of values
- Know the rules for naming variables, and the conventions for deciding on good variable names
- Know how to use the^ sep, and^ end^ keyword arguments with the^ print function.
- Know the definition and usage of operators and operands
- Know how to use the following operators: =, +, -, *, **, /, //, %
- Understand the distinction between a statement and an expression.
- Understand function calls as expressions that evaluate to their return values.
- Assigning a value is not stating an equality, like in math: it’s storing a value. A variable’s value can be updated (overwritten) by a new value using the assignment operator. Last time: How to read an assignment statement my_age = 31 my_age = 32 “my_age equals 32” “my_age becomes 32” “my_age gets 32” “the variable my_age takes on the value 32”
- Assigning a value is not stating an equality, like in math: it’s storing a value. A variable’s value can be updated (overwritten) by a new value using the assignment operator. Last time: How to read an assignment statement my_age = 31 my_age = 32 “my_age equals 32” “my_age becomes 32” “my_age gets 32” “the variable my_age takes on the value 32”
- Assigning a value is not stating an equality, like in math: it’s storing a value. A variable’s value can be updated (overwritten) by a new value using the assignment operator. Last time: How to read an assignment statement my_age = 31 my_age = 32 “my_age equals 32” “my_age becomes 32” “my_age gets 32” “the variable my_age takes on the value 32”
- Assigning a value is not stating an equality, like in math: it’s storing a value. A variable’s value can be updated (overwritten) by a new value using the assignment operator. Last time: How to read an assignment statement my_age = 31 my_age = 32 “my_age equals 32” “my_age becomes 32” “my_age gets 32” “the variable my_age takes on the value 32”
Variable Names
Variable Names
How do you use variables?
- Decide what value you want to store in the variable 2. Decide on a sensible name
- In your program, use the assignment operator to store that value in the variable