PTA编程题(python):计算分段函数

https://www.icourse163.org/learn/ZJU-1206456840

https://pintia.cn/problem-sets/1497398176843997184/problems/1497398251064791050

Python程序设计第二章(MOOC)
17 天
7-2 计算分段函数
分数 30
作者 陈春晖
单位 浙江大学

题目描述


提交代码

x = float(input())
result = 0
if x != 0:
    result = round(1 / (2 * x), 3)
print('g({0:.3f}) = {1:.3f}'.format(x, result))

执行结果

注意

代码第一行不能用int,要用float。否则报非零返回错误

posted @ 2022-05-19 21:18  孤舟浮岸  阅读(1611)  评论(0编辑  收藏  举报