本题目要求计算以下分段函数的值(x为从键盘输入的一个任意实数):

如果输入非数字,则输出“Input Error!”

输入格式:

在一行中输入一个实数x。

输出格式:

在一行中按”y=result”的格式输出,其中result保留两位小数。

输入样例:

-2

输出样例:

在这里给出相应的输出。例如:

y=3.00
def demo1(x):
if x > 1:
y = 2 * x + 1
elif x > -2:
y = 3
else:
y = -2 * x - 1
print("y={:.2f}".format(y)) try:
x = eval(input())
demo1(x)
except Exception as result:
print("Input Error!")

  

7-31 jmu-分段函数l (20 分)的更多相关文章

  1. PTA 邻接表存储图的广度优先遍历(20 分)

    6-2 邻接表存储图的广度优先遍历(20 分) 试实现邻接表存储图的广度优先遍历. 函数接口定义: void BFS ( LGraph Graph, Vertex S, void (*Visit)(V ...

  2. 第三次实验计算分段函数 第四次计算分段函数和循环NEW 第五次分支+循环加强版 实验报告

    一.实验题目,设计思路,实现方法 第四次分支+循环 加强版 (2-2计算个人所得税,2-7 装睡,2-8计算天数) 设计思路:2-2 用if-else的语句,与计算分段函数的题类似的做法:2-7 运用 ...

  3. 1011 World Cup Betting (20 分)

    1011 World Cup Betting (20 分) With the 2010 FIFA World Cup running, football fans the world over wer ...

  4. A1035 Password (20)(20 分)

    A1035 Password (20)(20 分) To prepare for PAT, the judge sometimes has to generate random passwords f ...

  5. pat 1011 World Cup Betting(20 分)

    1011 World Cup Betting(20 分) With the 2010 FIFA World Cup running, football fans the world over were ...

  6. PAT甲级——1152.Google Recruitment (20分)

    1152 Google Recruitment (20分) In July 2004, Google posted on a giant billboard along Highway 101 in ...

  7. PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...

  8. PAT甲级:1152 Google Recruitment (20分)

    PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...

  9. PAT乙级:1057 数零壹 (20分)

    PAT乙级:1057 数零壹 (20分) 题干 给定一串长度不超过 105 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数 N,然后再分析一 ...

随机推荐

  1. VSFTP服务搭建

    title date tags layout CentOS6.5 Vsftp服务安装与配置 2018-09-04 Centos6.5服务器搭建 post 1.安装vsftp服务 [root@local ...

  2. [LC] 451. Sort Characters By Frequency

    Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...

  3. 2. Unconstrained Optimization(2th)

    2.1 Basic Results on the Existence of Optimizers 2.1. DefinitionLet $f:U->\mathbb{R}$ be a functi ...

  4. locate及find查找命令

    在文件系统上查找符合条件的文件:       实现工具:locate,find locate:       依赖于事先构建好的索引库:       系统自动实现(周期性任务):       手动更新数 ...

  5. Object.prototype.toString.call(obj).slice(8,-1)

    1.Object.prototype.toString() 该方法返回描述某个对象数据类型的字符串,如自定义的对象没有被覆盖,则会返回“[object type]”,其中,type则是实际的对象类型. ...

  6. nginx做正向代理搭建bugfree

    下载地址: Nginx下载地址:http://download.csdn.net/detail/terrly88/9099117 bugfree下载地址:http://download.csdn.ne ...

  7. nc命令的用法

    1.什么是nc netcat(nc)是一个简单而有用的工具,可以使用tcp或者udp进行网络间读写数据,传输文件,接收发送数据,验证网络是否畅通. 2.命令行: 1) -l 用于指定nc将处于侦听模式 ...

  8. JDK和Spring中的设计模式

    创建型 1)工厂方法 Collection.iterator() 由具体的聚集类来确定使用哪一个Iterator 2)单例模式 Runtime.getRuntime() 3)建造者模式 StringB ...

  9. django框架基础-视图系统-长期维护

    ##################   什么是视图?     ####################### 视图: 1,一个视图函数(类),简称视图,是一个简单的Python 函数(类),它接受W ...

  10. file,path,uri互相转换

    uri 转 file :File file = new File(new URI(uri.toString())); uri 转 path: Path path = Files.get(uri); f ...