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='')
相关推荐
ZhengEnCi10 小时前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi12 小时前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽12 小时前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户83580861879113 小时前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L1 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅1 天前
海天线算法的前世今生
python·计算机视觉
韩师傅1 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L1 天前
LangGraph的MessageState and HumanMessage
python
韩师傅1 天前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L1 天前
python的类&继承
python