Re: [問題] 用C++寫程式

看板C_and_CPP作者時間15年前 (2009/12/15 11:28), 編輯推噓3(301)
留言4則, 4人參與, 最新討論串1/3 (看更多)
※ 引述《jazy6804 (豪大帥哥)》之銘言: : 1.寫一個程式輸入x,y座標值,判斷該點是在哪一個象限跟軸上 : 如:輸入(3.0,-2.5)印出即為第四象限;輸入座標(4.5,0),則 : 印出X軸 : 以上就這樣請高手幫忙>"<感謝 #!/usr/bin/env python # -*- coding: utf-8 -*- import re def coordinate(x, y): if x == 0.0 and y == 0.0: print '原點' elif x == 0.0 and y != 0.0: print 'y軸上' elif x != 0.0 and y == 0.0: print 'x軸上' elif x > 0.0 and y > 0.0: print '第一象限' elif x > 0.0 and y < 0.0: print '第四象限' elif x < 0.0 and y < 0.0: print '第三象限' elif x < 0.0 and y > 0.0: print '第二象限' def main(): while True: string = raw_input("請輸入座標:") r = re.compile(r'\((.*?),(.*?)\)') m = r.match(string) try: x = float(m.groups()[0]) y = float(m.groups()[1]) except: print "錯了啦!" continue coordinate(x, y) if __name__ == "__main__": main() else: pass -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.45.181.243

12/15 19:29, , 1F
推..XD
12/15 19:29, 1F

12/15 19:30, , 2F
上次只有一題就不知道幾面回文了, 這次有四題喔XD
12/15 19:30, 2F

12/15 19:32, , 3F
哈哈...推!
12/15 19:32, 3F

12/15 21:05, , 4F
還來XDD
12/15 21:05, 4F
文章代碼(AID): #1B9tBJMV (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1B9tBJMV (C_and_CPP)