Home  >  Article  >  Backend Development  >  How to find the value of a piecewise function using Python

How to find the value of a piecewise function using Python

coldplay.xixi
coldplay.xixiOriginal
2020-10-20 09:53:3530936browse

How to use Python to find the value of a piecewise function: first open the python editor; then use [If...else..] to make a judgment, the code is [x = eval(input()) y = 0 if x42e4fc965ef43a4f596b3828ac717ffb=1 and x9a31b63704823c3dc014cb9c6c0859ac=10

Write a program, enter x, output y

x = eval(input())
y = 0
if x<1:
    y = x
elif x>=1 and x<10:
    y = 2*x-1
else:
    y = 3*x-11
print(y)

Related free learning recommendations: python video tutorial

The above is the detailed content of How to find the value of a piecewise function using Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn