Chapter 3: Mathematical Functions and Strings

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/63

flashcard set

Earn XP

Description and Tags

These flashcards cover key concepts from Chapter 3 on Mathematical Functions and Strings in Python programming, helping to reinforce understanding and prepare for the exam.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

64 Terms

1
New cards

What is a function in Python?

A group of statements that performs a specific task.

2
New cards

What does the abs function do?

Returns the absolute value for x.

3
New cards

What is the purpose of the round function?

Returns the integer nearest to x.

4
New cards

What does the max function return?

The largest among the given numbers.

5
New cards

What does the min function return?

The smallest among the given numbers.

6
New cards

What is the behavior of the pow function?

Returns a raised to the power of b (a ** b).

7
New cards

Which module must be imported to use math functions?

math module.

8
New cards

How do you invoke the print function with an end argument?

By using print(item, end='anyEndingString').

9
New cards

What is a string in Python?

A sequence of characters, enclosed in single or double quotes.

10
New cards

What method is used to concatenate two strings?

The + operator.

11
New cards

What is an escape sequence?

A backslash followed by a character that represents a special character.

12
New cards

How can you represent a newline in a string?

Using the escape sequence \n.

13
New cards

What does the math.sqrt function compute?

The square root of a number.

14
New cards

What is the formula to calculate the distance between two points?

distance(p1x, p1y, (p2x, p2y)) = ((p2x - p1x)^2 + (p2y - p1y)^2)^0.5.

15
New cards

What does the format function do in Python?

Formats numbers and strings into a specified format.

16
New cards

How do you convert a number to a string in Python?

Using the str() function.

17
New cards

What does the ceil function do?

Rounds x up to its nearest integer.

18
New cards

What does the floor function do?

Rounds x down to its nearest integer.

19
New cards

What does the round function do with half values?

Returns the nearest even integer if x is equally close to two integers.

20
New cards

What conversion does the degrees function perform in the math module?

Converts radians to degrees.

21
New cards

What conversion does the radians function perform in the math module?

Converts degrees to radians.

22
New cards

How many cents are in a dollar?

100 cents.

23
New cards

What are the U.S. monetary units in cents?

1 dollar = 100 cents, 1 quarter = 25 cents, 1 dime = 10 cents, 1 nickel = 5 cents.

24
New cards

What will the input '11.56' produce when multiplied by 100?

1156, it represents cents.

25
New cards

What are the coordinate inputs for calculating triangle angles?

Three points p1(x1, y1), p2(x2, y2), and p3(x3, y3).

26
New cards

What does the acos function return?

The arc cosine of x, in radians.

27
New cards

How do you format a number with two decimal points?

Using the format function: format(number, '.2f').

28
New cards

What string specifies left justification in formatting?

The '<' symbol.

29
New cards

What string specifies right justification in formatting?

The '>' symbol.

30
New cards

How would you display a string in a width of 20?

Using format(string, '20s').

31
New cards

How do you calculate the area of a circle given its radius in Python?

Using the formula area = math.pi * radius ** 2.

32
New cards

What will happen if you enter 10.03 as a float and multiply by 100?

You might get 1002.9999999999999, leading to potential precision loss.

33
New cards

How do you concatenate strings in Python?

Using the + operator or augmented assignment +=.

34
New cards

What does using the print function with the end argument allow you to do?

Control the output ending, preventing automatic newline.

35
New cards

What does the format specifier '10.2f' mean?

Formats a float with a width of 10 and precision of 2.

36
New cards

How do you format an integer using the format function?

Using format(integer, 'd' or '10d').

37
New cards

What type of quotes are recommended for multi-character strings?

Double quotes (" ").

38
New cards

What is the format for single-character strings?

Single quotes (' ').

39
New cards

What does the str function do?

Converts a number or other type to a string.

40
New cards

How can you read a string input from the console?

Using the input() function.

41
New cards

What symbol do you use to include a double quote in a string?

The escape sequence \

42
New cards

What does the print function default to when printing?

Prints with a newline at the end.

43
New cards

How do you display multiple items on the same line using print()?

By using end=' ' in the print function.

44
New cards

In what scenario will you get a syntax error with print?

If quotes are not closed properly.

45
New cards

What does eval do in input?

Evaluates the input as a Python expression.

46
New cards

How do you find the number of remaining cents after calculating dollars?

Using the modulus operator (%) with 100.

47
New cards

How do you calculate the maximum number of quarters from remaining cents?

By dividing remainingCents by 25.

48
New cards

What is the default justification for strings in Python?

Left justified.

49
New cards

How can you avoid precision loss in float to integer conversion?

By entering the amount as an integer representing cents.

50
New cards

What will format(0.53457, '10.2%') produce?

53.46%.

51
New cards

What does the backslash character \ indicate in a string?

It represents the escape character.

52
New cards

What will round(2.675, 2) return?

2.67 due to floating point precision issues.

53
New cards

What problem is highlighted with float precision when entering amounts?

Possible loss of precision when converting to int.

54
New cards

How can you format the output for displaying money amounts correctly?

Using format with two decimal points or rounding.

55
New cards

What are the built-in functions that are always available?

eval, input, print, int.

56
New cards

What does the print statement do with \f?

Forces the printer to print from the next page.

57
New cards

How can you read three strings in one go from console input?

s1 = input(), s2 = input(), s3 = input() with prompts.

58
New cards

What character signifies the end of a line in a string?

\n (newline character).

59
New cards

What will the expression min(3, 5, 1, 7, 4) return?

1, the smallest value.

60
New cards

What are the two numerical variables returned when using pow(2, 3)?

8, the result of 2 raised to the power of 3.

61
New cards

What will round(3.52) return?

4, rounding to the nearest integer.

62
New cards

How do you implement comments in Python code?

Using the # symbol.

63
New cards

What does the end argument in print prevent?

Automatic newline after the output.

64
New cards

How do you simplify the variable handling for displaying results in a table?

By using formatting constants for output representation.