Zybooks L3 Flashcards

1
Q

print floating number two digits after decimal

A

print(f’{myFloat:.2f}’)
print(f’{math.pi:.2f}’)
print(f’{(7.0/3.0):.2f}’) outputs 2.33.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

int(input())

A

when working with whole numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

float(input())

A

when working with decimals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

expression

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

literal

A

a specific value in code like 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

operator

A

a symbol that performs a built-in calculation, like +, which performs addition. Common programming operators are shown below

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

exponent operator: **

A

x ** y (x to the power of y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

compound operators

A

shorthand way to update a variable
age += 1 age = age + 1
age -= 1
age *= 1
age /= 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The division operator / performs division and returns a floating-point number.

A

20 / 10 is 2.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

floor division operator // can be used to round down the result of a floating-point division to the closest smaller whole number value.

A

20 // 10 is 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The modulo operator (%) evaluates the remainder of the division of two integer operands

A

9 % 5 is 4. Reason: Since 9 = 5 * 1 + 4, the floor division 9 // 5 results in 1, and the remainder is 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

module

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

import statement

A

referencing and making another module available for use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

python’s randrange()

A

method generates random integers within a specified range
random.randrange(10) returns an integer with 10 possible values: 0, 1, 2, …, 8, 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

python defined range code:
randint(min,max)

A

print(random.randint(12,20))
returns a randon integer between 12 and 20 inclusive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

python defined range code:
randrange(min,max)

A

returns a random integer between min and max -1 inclusive
print(random.randrange(12,20)
- returns a random integer between 12 and 19 inclusive

17
Q

seed // seed() method

A

program can specify the seed by calling seed() method. i.e. random.seed(5) // with a specific seed, each program run yields the same sequence of psuedo-random numbers
- for the first call to any random method (no previous random method exists), computer uses built-in integer based on current time to help generate a random number

18
Q

unicode

A

python uses Unicode to represent every possible character as a unique number, known as a code point

19
Q

escape sequence

A

the interpreter recognizes \ as the start of a special character’s two-item sequence
- print(‘\home\users\’) -> \home\users\
- print(‘Name: John O'Donald’) -> Name: John O’Donald
- print(“He said, "Hello friend!"”) -> He said, “Hello friend!”
- print(‘My name…\nIs John…’) -> My name…
Is John…
- print(‘1. Bake cookies\n\t1.1. Preheat oven’) ->
1. Bake cookies
1.1. Preheat oven

20
Q

raw string

A

escape sequences can be ignored
- my_raw_string = r’This is a \n 'raw' string’
This is a \n 'raw' string