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='')
相关推荐
cup115 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi007 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵9 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf10 小时前
Agent 流程编排
后端·python·agent
copyer_xyf10 小时前
Agent RAG
后端·python·agent
copyer_xyf10 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf10 小时前
Agent 记忆管理
后端·python·agent
星云穿梭1 天前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵1 天前
用 Pygame 实现 15 puzzle
python·数学·游戏