Module: (Python) Real numbers


Problem

4/11

Input and output of real numbers

Theory Click to read/hide

Input

In order to enter a real number using the input () function, it is necessary to convert the character string (which is the result of the function \(input()\)) into a real number using the function \(float()\):
x = float(input())
If you need to enter several values from one line at once, then we use the same method as for integers:
x, y = map(float, input().split())

Output

When outputting real numbers, 16 decimal places are displayed by default. This format is not always necessary. If you want to reduce the output format, then format output is used. To do this, the format method is applied to the string that we want to output. And inside the line formats are written in braces after the colon
Example:
x=1/6
print("{:f}".format(x))  # format f prints 6 digits in fractional part by default
print("{:.3f}".format(x)) # .3 indicates that it is necessary to print 3 characters after the period
print("{:12.4e}".format(x)) #12.4 - the first number (12) specifies the total number of positions to display the number, the second (4) - the number of digits in the fractional part. Format e - displays a number in scientific format
The screen displays
0.166667
0.167
  1.6667e-01

Problem

Complete the tasks in order:
1. On the third line, format the y variable output using formatted output, with the default number of characters in the fractional part
2. In the fourth line, format the output of the y variable so that the entire number is displayed in 10 positions, while 4 digits are allocated to the fractional part
3. In the fifth line, format the output of the y variable so that the number is displayed in a scientific format with three digits in the fractional part