设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【Python 第24课】 if的嵌套

[复制链接]

0

主题

2

好友

72

积分

注册会员

Rank: 2

楼主
发表于 2018-4-6 10:45:24 |显示全部楼层
方法一:
  1. x=eval(input('please enter the abscissa'))
  2. y=eval(input('please enter the ordinate'))
  3. if x>0:
  4.     if y>0:
  5.         print('First quadrant')
  6.     elif y<0:
  7.         print('Fourth quadrant')
  8.     else:
  9.         print('The number is in active abscissa')
  10. elif x<0:
  11.     if y>0:
  12.         print('Second quadrant')
  13.     elif y<0:
  14.         print('Third quadrant')
  15.     else:
  16.         print('The number is in negative abscissa')
  17. else:
  18.     if y>0:
  19.         print('The number is in active ordinate')
  20.     elif y<0:
  21.         print('The number is in negative ordinate')
  22.     else:
  23.         print('The center is waiting for you!!!')
复制代码
回复

使用道具 举报

0

主题

2

好友

72

积分

注册会员

Rank: 2

沙发
发表于 2018-4-6 10:58:27 |显示全部楼层
这是看了看大家的代码,得到的灵感,还可以练练函数~
  1. def quadrant(x,y):   
  2.     if x>0:
  3.         if y>0:
  4.             print('First quadrant')
  5.         elif y<0:
  6.             print('Fourth quadrant')
  7.         else:
  8.             print('The number is in active abscissa')
  9.     elif x<0:
  10.         if y>0:
  11.             print('Second quadrant')
  12.         elif y<0:
  13.             print('Third quadrant')
  14.         else:
  15.             print('The number is in negative abscissa')
  16.     else:
  17.         if y>0:
  18.             print('The number is in active ordinate')
  19.         elif y<0:
  20.             print('The number is in negative ordinate')
  21.         else:
  22.             print('The center is waiting for you!!!')
  23. x=eval(input('please enter the abscissa'))
  24. y=eval(input('please enter the ordinate'))
  25. quadrant(x,y)
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-18 20:35 , Processed in 0.024521 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部