Print function and calculation segmentation function

This topic requires calculating the value of the following piecewise function f(x):Insert picture description here

Input format:

Enter the real number x in one line.

Output format:

In one line, output in the format of "f(x) = result", in which x and result both retain one decimal place.

Input example 1:

10
Output example 1:

f(10.0) = 0.1
Input example 2:

0
output example 2:

f(0.0) = 0.0

a= float(input())
if a==0:
   print("f(0.0) = 0.0")
else:
    print("f({:.1f}) = {:.1f}".format(a,1/a))

Summary of print function usage

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

objects-plural, which means that multiple objects can be output at once. When outputting multiple objects, you need to use, to separate.

sep-used to separate multiple objects, the default value is a space.

end-used to set the ending. The default value is the newline character\n, we can change to other strings.

file-the file object to be written.

flush-Whether the output is cached is usually determined by the file, but if the flush keyword argument is True, the stream will be forced to flush.

Note:
print is a function in Python 3.x, but not a function in Python 2.x, just a keyword.

(Keywords: Some words in the Python language that have been assigned specific meanings. Developers are required to not use these reserved words as identifiers to name variables, functions, classes, templates, and other objects when developing programs.)

(It should be noted that since Python is strictly case-sensitive, keywords (reserved words) are no exception)

(If you use a reserved word in Python as an identifier, the interpreter will prompt an error message of "invalid syntax")

Guess you like

Origin blog.csdn.net/m0_46407213/article/details/109141571