1/63
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.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a function in Python?
A group of statements that performs a specific task.
What does the abs function do?
Returns the absolute value for x.
What is the purpose of the round function?
Returns the integer nearest to x.
What does the max function return?
The largest among the given numbers.
What does the min function return?
The smallest among the given numbers.
What is the behavior of the pow function?
Returns a raised to the power of b (a ** b).
Which module must be imported to use math functions?
math module.
How do you invoke the print function with an end argument?
By using print(item, end='anyEndingString').
What is a string in Python?
A sequence of characters, enclosed in single or double quotes.
What method is used to concatenate two strings?
The + operator.
What is an escape sequence?
A backslash followed by a character that represents a special character.
How can you represent a newline in a string?
Using the escape sequence \n.
What does the math.sqrt function compute?
The square root of a number.
What is the formula to calculate the distance between two points?
distance(p1x, p1y, (p2x, p2y)) = ((p2x - p1x)^2 + (p2y - p1y)^2)^0.5.
What does the format function do in Python?
Formats numbers and strings into a specified format.
How do you convert a number to a string in Python?
Using the str() function.
What does the ceil function do?
Rounds x up to its nearest integer.
What does the floor function do?
Rounds x down to its nearest integer.
What does the round function do with half values?
Returns the nearest even integer if x is equally close to two integers.
What conversion does the degrees function perform in the math module?
Converts radians to degrees.
What conversion does the radians function perform in the math module?
Converts degrees to radians.
How many cents are in a dollar?
100 cents.
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.
What will the input '11.56' produce when multiplied by 100?
1156, it represents cents.
What are the coordinate inputs for calculating triangle angles?
Three points p1(x1, y1), p2(x2, y2), and p3(x3, y3).
What does the acos function return?
The arc cosine of x, in radians.
How do you format a number with two decimal points?
Using the format function: format(number, '.2f').
What string specifies left justification in formatting?
The '<' symbol.
What string specifies right justification in formatting?
The '>' symbol.
How would you display a string in a width of 20?
Using format(string, '20s').
How do you calculate the area of a circle given its radius in Python?
Using the formula area = math.pi * radius ** 2.
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.
How do you concatenate strings in Python?
Using the + operator or augmented assignment +=.
What does using the print function with the end argument allow you to do?
Control the output ending, preventing automatic newline.
What does the format specifier '10.2f' mean?
Formats a float with a width of 10 and precision of 2.
How do you format an integer using the format function?
Using format(integer, 'd' or '10d').
What type of quotes are recommended for multi-character strings?
Double quotes (" ").
What is the format for single-character strings?
Single quotes (' ').
What does the str function do?
Converts a number or other type to a string.
How can you read a string input from the console?
Using the input() function.
What symbol do you use to include a double quote in a string?
The escape sequence \
What does the print function default to when printing?
Prints with a newline at the end.
How do you display multiple items on the same line using print()?
By using end=' ' in the print function.
In what scenario will you get a syntax error with print?
If quotes are not closed properly.
What does eval do in input?
Evaluates the input as a Python expression.
How do you find the number of remaining cents after calculating dollars?
Using the modulus operator (%) with 100.
How do you calculate the maximum number of quarters from remaining cents?
By dividing remainingCents by 25.
What is the default justification for strings in Python?
Left justified.
How can you avoid precision loss in float to integer conversion?
By entering the amount as an integer representing cents.
What will format(0.53457, '10.2%') produce?
53.46%.
What does the backslash character \ indicate in a string?
It represents the escape character.
What will round(2.675, 2) return?
2.67 due to floating point precision issues.
What problem is highlighted with float precision when entering amounts?
Possible loss of precision when converting to int.
How can you format the output for displaying money amounts correctly?
Using format with two decimal points or rounding.
What are the built-in functions that are always available?
eval, input, print, int.
What does the print statement do with \f?
Forces the printer to print from the next page.
How can you read three strings in one go from console input?
s1 = input(), s2 = input(), s3 = input() with prompts.
What character signifies the end of a line in a string?
\n (newline character).
What will the expression min(3, 5, 1, 7, 4) return?
1, the smallest value.
What are the two numerical variables returned when using pow(2, 3)?
8, the result of 2 raised to the power of 3.
What will round(3.52) return?
4, rounding to the nearest integer.
How do you implement comments in Python code?
Using the # symbol.
What does the end argument in print prevent?
Automatic newline after the output.
How do you simplify the variable handling for displaying results in a table?
By using formatting constants for output representation.