Use the help() function to find out about the round() command.Explain and demonstrate how to use it with more than one argument toproduce different results.
Question
Use the help() function to find out about the round() command.Explain and demonstrate how to use it with more than one argument toproduce different results.
Solution
The help() function in Python is a built-in function that can be used to display the documentation of modules, functions, classes, keywords etc. If the help function is passed without an argument, then the interactive help utility starts up on the console.
Let's use the help() function to find out about the round() function.
help(round)
This will output:
Help on built-in function round in module builtins:
round(number, ndigits=None)
Round a number to a given precision in decimal digits.
The return value is an integer if ndigits is omitted or None. Otherwise
the return value has the same type as the number. ndigits may be negative.
The round() function in Python rounds a number to a given precision in decimal digits. It takes two parameters:
- number - the number to be rounded
- ndigits (Optional) - number up to which the given number is rounded; defaults to None
If ndigits is omitted or None, the return value is an integer. If ndigits is specified, the return value has the same type as the number. ndigits may be negative.
Here's how to use it:
# rounding a number
print(round(5.76543)) # Output: 6
# rounding a number to 2 decimal places
print(round(5.76543, 2)) # Output: 5.77
# rounding a number to -2 decimal places
print(round(567.76543, -2)) # Output: 600.0
In the first example, round(5.76543) returns 6 because without a second argument, round() returns the nearest even integer.
In the second example, round(5.76543, 2) returns 5.77 because it rounds the number to the nearest 2 decimal places.
In the third example, round(567.76543, -2) returns 600.0 because when the second argument is negative, it rounds the number to the nearest 10's place (or 100's place for -2, 1000's place for -3, etc.).
Similar Questions
Question 1Read the description given by1help(round)Then select the function call(s) below that run without error. You can check your answers by running the code in the Python Shell.1 pointround(45.345, 2)round(45.345, 2)round(45)round(45)round(45.8)round(45.8)round()round()round(45.345, 2, 5)round(45.345, 2, 5)
Here is the help for function roundround:7456123 same type as the number. ndigits may be negative. round(number[, ndigits]) -> number Round a number to a given precision in decimal digits (default 0 digits). This returns an int when called with one argument, otherwise the Help on built-in function round in module builtins: round(...) Select the number of arguments that function roundround can take.
round ( ) and truncate( ) are just the same.Group of answer choicesTrueFalse
orrect answerWhat will be the output of the following Python expression?round(4.576)Options454.64.5
OK, let's see if I can explain this. When you round off, you change the value of the number,except if you round off a zero. Following the old rules, you can round a number down in valuefour times (rounding with one, two, three, four) compared to rounding it upwards five times(five, six, seven, eight, nine). Remember that "rounding off" a zero does not change the value ofthe number being rounded off
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.