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='')
相关推荐
dev派15 小时前
AI Agent 系统中的常用 Workflow 模式(2) Evaluator-Optimizer模式
python·langchain
前端付豪17 小时前
AI 数学辅导老师项目构想和初始化
前端·后端·python
用户03321266636717 小时前
将 PDF 文档转换为图片【Python 教程】
python
悟空爬虫19 小时前
UV实战教程,我啥要从Anaconda切换到uv来管理包?
python
dev派19 小时前
AI Agent 系统中的常用 Workflow 模式(1)
python·langchain
明月_清风21 小时前
从“能用”到“专业”:构建生产级装饰器与三层逻辑拆解
后端·python
曲幽1 天前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic
用户8356290780511 天前
Python 实现 PowerPoint 形状动画设置
后端·python
ponponon2 天前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly2 天前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent