PTA题目|象限的判断(python)

题目要求

输入一对坐标,输出它在直角坐标系中的象限。

输入格式:

输入坐标(x,y),(假设输入的x或y坐标值一定不会为0)如:(3.5,-2)。

输出格式:

输出对应的象限,如:第四象限

输入样例:

在这里给出一组输入。例如:

复制代码
(3.5,-2)

输出样例:

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

复制代码
第四象限

代码实现

python 复制代码
input1 = input()
x, y = map(float, input1.strip('()').split(','))
if x > 0 and y > 0:
    quadrant = "第一象限"
elif x < 0 and y > 0:
    quadrant = "第二象限"
elif x < 0 and y < 0:
    quadrant = "第三象限"
elif x > 0 and y < 0:
    quadrant = "第四象限"
print(quadrant,end='')
相关推荐
门框研究员16 小时前
解锁Python的强大能力:深入理解描述符
python
子不语18017 小时前
Python——函数
开发语言·python
daidaidaiyu18 小时前
一文入门 LangChain 开发
python·ai
JJ1M819 小时前
用 Python 快速搭建一个支持 HTTPS、CORS 和断点续传的文件服务器
服务器·python·https
汤姆yu19 小时前
基于python大数据的小说数据可视化及预测系统
大数据·python·信息可视化
x***J34819 小时前
Python多线程爬虫
开发语言·爬虫·python
m***D28619 小时前
Python网络爬虫实战案例
开发语言·爬虫·python
ID_1800790547320 小时前
基于 Python 的淘宝商品详情数据结构化解析:SKU、价格与库存字段提取
开发语言·数据结构·python
Laughtin20 小时前
终端Python环境的选择与切换
开发语言·python
JHC00000020 小时前
Python PDF 相关操作
开发语言·python·pdf