Python重寫C語言程式100例--Part2__Python

來源:互聯網
上載者:User
[python]  view plain copy print ? '''''題目:輸入某年某月某日,判斷這一天是這一年的第幾天。  1.程式分析:以3月5日為例,應該先把前兩個月的加起來,然後再加上5天即本年的第幾天,特殊        情況,閏年且輸入月份大於3時需考慮多加一天。  2.程式原始碼:  '''   year = int(raw_input('year:\n'))   month = int(raw_input('month:\n'))   day = int(raw_input('day:\n'))      months = (0,31,59,90,120,151,181,212,243,273,304,334)   if 0 <= month <= 12:       sum = months[month - 1]   else:       print 'data error'   sum += day   leap = 0   if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):       leap = 1   if (leap == 1) and (month > 2):       sum += 1   print 'it is the %dth day.' % sum  
[python]  view plain copy print ? '''''  【程式5】  題目:輸入三個整數x,y,z,請把這三個數由小到大輸出。  1.程式分析:我們想辦法把最小的數放到x上,先將x與y進行比較,如果x>y則將x與y的值進行交換,        然後再用x與z進行比較,如果x>z則將x與z的值進行交換,這樣能使x最小。  2.程式原始碼:  '''   l = []   for i in range(3):       x = int(raw_input('integer:\n'))       l.append(x)   l.sort()   print l  

  [python]  view plain copy print ?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.