Ch 2 Variables and Assignments ver 2

Ace your homework & exams now with Quizwiz!

5/10

0.5

x = 5 x = x + 7

12

num_atoms is initially 7. What is num_atoms after: num_atoms *= 2?

14

x = 2 y = 3 x = x * y x = x * y

18

5.0//2

2.0

12/4

3.0

596%10

6

identifier (variable name)

Also called a name, is a sequence of letters (a-z,A-Z), underscores(_), and digits(0-9). Identifiers must start with a letter or an underscore.

Reserved Words

Also called keywords, are words that are part of the language and cannot be used as a programmer-defined name. Many programs automatically color a program's reserved words

escape sequence

An escape character, \, followed by one or more printable characters used to designate a nonprintable character.

Evaluates

An expression evaluates to a value, which replaces the expression

type()

Built-in function that prints the type of an object

What is total_count after executing the following? num_items = 5 total_count = 1 + (2 * num_items) * 4

41

78%10`

8

x = 9 y = x + 1 What is x?

9

float

A data type in programming that contains a floating point value, more commonly referred to as a decimal value, like 1.5 or 3.14

Module

A file containing Python code that can be used by other modules or scripts

Script

A file where programmers typically write Python program code, and executes the code by passing the script as input to the Python interpreter.

scientific notation

A floating-point literal using scientific notation is written using an e preceding the power-of-10 exponent, as in 6.02e23 to represent 6.02x1023. The e stands for exponent. Likewise, 0.001 is 1x10-3, so it can be written as 1.0e-3.

\\

Backslash (\) print('\\home\\users\\') \home\users\

\"

Double-quote (") print("He said, \"Hello friend!\".") He said, "Hello friend!".

y = 30 x = y + 2 x = x + 1

33

math module

Supports advanced math operations

Case Sensitive

Uppercase and lowercase letters are different. Cat and cat hat and Hat

Variable

a named item used to hold a value x num_people

literal

a specific value in code, like 2

Operator

a symbol that performs a built-in calculation, like +, -,*,/,**

2x

not valid

OverflowError

occurs when a value is too large to be stored in the memory allocated by the interpreter

backslash

upon reaching a \, the interpreter recognizes that item as the start of a special character's two-item sequence and then looks at the next item to determine the special character.

Floored division operator //

used to round down the result of a floating-point division to the closest whole number value 20//10=2 50//50=1 5//10=0 (remainder 5 is thrown away)

2

valid

2 * (x - y)

valid

x

valid

x + 1

valid

x=1

valid

x=y

valid

x=y+2

valid

y + 2 * z

y+(2*z)

Complete this statement to increment y: y = _____

y+1

6 + num_items

yes

num_atoms is initially 7. What is num_atoms after: num_atoms += 5?

12

51%2

1

x = 9 y = x + 1 What is y?

10

x = 9 y = x + 1 x = 5 What is y?

10

What is the output of print('10...\n9...')

10... 9...

function

a list of statements that can be executed by simply referring to the function's name

Exponent

**, as in x**y

Multiplication

*, as in x*y

Addition

+, as in x+y

Subtraction

-, as in x-y

assignment statement

-assigns a variable with a value x=5 means x is assigned with 5 and keeps that value during subsequent statements, until x is assigned again. -left side must be a variable -right side can be an expression -A statement can be x=5, y=x, z=x+2

Division

/,as in x/y

50%2

0

100%(1//2)

error

100/0

error

Modulo Operator

evaluates to the remainder of the division of the two integer operands 23%10 is 3

Import

executes the contents of a file containing Python code and makes the definitions from that file available

A person's height in centimeters

float

The average number of kids per household

float

The current temperature in Celsius

float

incrementing

increasing a variable's value by 1, as in x=x+1

The number of cars in a parking lot

int

The number of hairs on a person's head

int

3rd_place

invalid

num cars

invalid

x+1=3

invalid

x+y=y+x

invalid

5t

no

6 x num_items

no

n factorial n!

no. Python does not use ! symbol for factorial

argument

the item passed to a function. some functions have multiple arguments.

function call

the process of invoking a function

module

Python code located in another file

\'

Single-quote (') print('Name: John O\'Donald') Name: John O'Donald

\t

Tab (indent) print('1. Bake cookies\n\t1.1. Preheat oven') 1. Bake cookies 1.1. Preheat oven

Dot notation

Used to reference an object in an imported module

Unicode

Used to represent every possible character as a unique number, known as code point

Is the following an error? num_years = 1,999,999,999

Yes. -Commas are not allowed in an integer literal.

What is the output of print('\\c\\users\\juan')

\c\users\juan

expression

a combination of items, like variables, literals, operators, and parentheses, that evaluates to a value, like 2*(x+1)

floating-point number

a real number, like 98.6, 0.0001, or -666.667. Floating-point refers to the decimal point being able to appear anywhere in the number

Given a 16-digit credit card number stored in x, which gets the last (rightmost) four digits? (Assume the fourth digit from the right is non-zero).

x%10000

The negative of user_val: -user_val

yes

total_days / 12

yes

What is the output of print('My name is \'Tator Tot\'.')

My name is 'Tator Tot'.

\n

Newline print('My name...\nIs John...') My name... Is John...

2+(xy)

not valid

y=x+1

not valid

Division operator /

performs division and returns as a floating-point number. 20/10=2.0 50/50=1.0 5/10=0.5

floating-point literal

written with the fractional part even if that fraction is 0, as in 1.0, 0.0, or 99.0

__numcars2

valid

_num_cars

valid

numCars

valid

num_cars1

valid

third_place

valid


Related study sets

Week 1 - Understanding Security Threats

View Set

pf insurance (Personal Finance 12)

View Set

World History: The Age of Revolution

View Set

Con 317 Midterm, CON 317 Final (quizzes only)

View Set

Sterile Compounding PE Section 4

View Set

BIOL 1610 Mitosis & Meiosis Quiz

View Set