Python Exam 2 Flashcards

1
Q

parameter

A

value passed into a function by its caller
def <name>(<name>):
<statement(s)></name></name>

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

multiple parameters

A

a function can accept multiple parameters.

Separate each parameter by a comma

When calling has to have every parameter needed

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

value semantics

A

When numbers and strings are passed as parameters, their values are copied

Modifying the parameters will not affect the variable passed in

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

math.ceil(value)

A

rounds up

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

math.floor(value)

A

rounds down

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

math.log(value)

A

logarithm
requires import math

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

math.sqrt(value)

A

square root
requires import math

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

math.sinh(value)
math.cosh(value)
math.tanh(value)

A

hyperbolic sine/cosine/tangent of an angle in radians
requires import math

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

math.degrees(value)
math.radians(value)

A

convert to degrees and radians and back
requires import math

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

e

A

2.7182818
requires import math

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

pi

A

3.1515926
requires import math

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

abs(value)

A

absolute value

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

min(value1, value2)

A

smallest of 2 values

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

max(value1, value2)

A

largest of 2 values

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

round(value)

A

nearest whole number

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

math functions

A

imply calling these functions produces not visible result

Math function calls use a python feature called return values that cause them to be treated as expressions

The program runs the function, computes the answer, and then replaces the call with its computer result value

To see the result, we must print it or store it in a variable

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

return

A

to send a value as the result of a function call

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

why return and not print

A

we can compute several things before printing

19
Q

what does import random do?

A

it imports the random module

20
Q

random functions taught in class

A

random.random()
random.randint(min,max)

21
Q

random.random()

A

returns a random float in the range [0.0, 1.0)

22
Q

random.randint(min,max)

A

returns a random int in the rand [min, max)

23
Q

strings

A

a type that stores a sequence of text characters
can concatenate strings using +
can multiply strings using *
can print strings and get them as input from the command line

24
Q

index

A

characters of a string are numbered with 0-based indexes
first character’s index:0
Last character’s index: 1 less than len of string or -1

25
Q

accesssing characters in a string

A

string[index]

26
Q

accessing sub strings

A

part = string[start:stop]

27
Q

in this string name = “Mary”, how do you print “ar” ?

A

mid = name[1:3]
print(mid)

28
Q

in this string name = “Mary”, how do you print “Mar” ?

A

mid = name[:3]
print(mid)

29
Q

in this string name = “Mary”, how do you print “ary” ?

A

mid = name[1:]
print(mid)

30
Q

find a string

A

find(str)
returns index of where found (first entry only)
returns -1 if not found

31
Q

lower()

A

a new string with all lowercase letters

32
Q

upper()

A

a new string with all uppercase letters

33
Q

len(string)

A

the length of the string

34
Q

endswith(str)

A

whether a string ends with a specified substring. case sensitive

35
Q

startswith(str)

A

whether a string starts with a specified substring
case sensitive

36
Q

islower()

A

whether all the characters in the string are lowercase

37
Q

isupper()

A

whether all the characters in the string are uppercase

38
Q

isalpha()

A

whether the string contains only alphanumeric characters

39
Q

isdigit()

A

whether the string contains only digits

40
Q

f-strings

A

build formatted strings by embedding expressions into strings
ex: print(f”Hello, {name}”) with name being a variable

41
Q

ASCII values

A

char values assigned to numbers internally by the computer

42
Q

ord

A

ordinal value. the number version of a letter

43
Q

chr

A

character value. the letter corresponding to a number

44
Q
A