CPIT 110 - (Chapter 3/Mathematical Functions and Strings)

0.0(0)
Studied by 1 person
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/54

encourage image

There are no tags or description

Looks like no tags are added yet.

55 Terms

1
New cards

Function

A group of statements that performs a specific task

2
New cards


Python, as well as other programming languages, provides

Library of functions

3
New cards

Built-in functions

Always available in the Python interpreter

4
New cards

abs(x)

Returns the absolute value for x

5
New cards

max(x1, x2, …)

Returns the largest among x1, x2, …

6
New cards

min(x1, x2, …)

Returns the smallest among x1, x2, …

7
New cards

pow(a, b)

Returns ab. Same as a ** b

8
New cards

round(x)

Returns an integer nearest to x (if x is equally close to two integers, the even one is returned)

9
New cards

round(x, n)

Returns the float value rounded to n digits after the decimal point

10
New cards

Some of the most popular mathematical functions are defined
in the Python math module

Including trigonometric functions, representation functions, logarithmic functions, angle conversion functions, etc

11
New cards

fabs(x)

Returns the absolute value for x as a float

12
New cards

ceil(x)

Rounds x up to its nearest integer and returns that integer

13
New cards

floor(x)

Rounds x down to its nearest integer and returns that integer

14
New cards

exp(x)

Returns the exponential function of x(ex)

e = (Euler's number) that is approximately equal to 2.71828

15
New cards

log(x)

Returns the natural logarithm of x

16
New cards

log(x, base)

Returns the logarithm of x for the specified base

17
New cards

sqrt(x)

Returns the square root of x

18
New cards

sin(x)

Returns the sine of x; x would represent an angle in radians

19
New cards

asin(x)

Returns the angle in radians for the inverse of sine

20
New cards

cos(x)

Returns the cosine of x; x would represent an angle in radians

21
New cards

acos(x)

Returns the angle in radians for the inverse of cosine

22
New cards

tan(x)

Returns the tangent of x; x would represent an angle in radians

23
New cards

degrees(x)

Converts angle x from radians to degrees

24
New cards

radians(x)

Converts angle x from degrees to radians

25
New cards

String

A sequence of characters and can include text and numbers

26
New cards

String values must be enclosed in

Matching single quotes (') or double quotes (")

27
New cards

Double quotes (") for a string with

More than one character

28
New cards

Single quotes (') for a string with

A single character or an empty string

29
New cards

Escape sequence

Backslash (\) followed by a letter or a combination of digits

30
New cards

\b

Backspace

31
New cards

\t

Tab

32
New cards

\n

Newline, line break, or end-of-line (EOL) character; signifies the end of a line

33
New cards

\’

Single quote

34
New cards

\”

Double quote

35
New cards

\f

Character that forces the printer to print from the next page/line

36
New cards

\r

Character that is used to move the cursor to the first position on the same line

37
New cards

When you use the print function, it automatically prints

A linefeed (\n) to cause the output to advance to the next line

38
New cards

‘+’ is an operator that can be used to add two numbers and

Be used to concatenate (join) two strings

39
New cards

The augmented assignment += operator can be used for

String concatenation

40
New cards

You can use the format function (.f) to format a number or

A string and return the result as a string

41
New cards

Width specifier

The width is automatically set to the size needed for formatting the number (defaults to 0)

42
New cards

Conversion code %

To format a number as a percentage

43
New cards

The format of a number is

Right justified

44
New cards

When putting the symbol ‘<‘ in the format specifier, it will

Specify that the item be left-justified in the resulting format within the specified width

45
New cards

Conversion code ‘d’

To format an integer in decimal

46
New cards

Conversion code ‘s’

To format a string with a specified width

47
New cards

To right-justify a string,

Put the symbol ‘>’ in the format specifier

48
New cards

By default, a string is

Left justified

49
New cards

If the string is longer than the specified width,

The width is automatically increased to fit the string

50
New cards

10.2f

Format the float item with width 10 and precision 2

51
New cards

5d

Format the integer item in decimal with width 5

52
New cards

10.2%

Format the number in decimal

53
New cards

50s

Format the string item with width 50

54
New cards

<10.2f

Left-justify the formatted item

55
New cards

>10.2f

Right-justify the formatted item