How to find the value of a piecewise function using Python

coldplay.xixi
Release: 2020-10-20 09:53:35
Original
30949 people have browsed it

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 x<1:y x="" elif="">=1 and x<10:y=2*x].

How to find the value of a piecewise function using Python

How to use Python to find the value of a piecewise function:

There is a function

y={ x x<1

{2x-1 1<=x<10

{3x-11 x>=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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template