Created
March 26, 2016 19:11
-
-
Save renyuanL/7af1a2800f10a9f43e22 to your computer and use it in GitHub Desktop.
solving a math problem for Jimmy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#---------------------------------------------- | |
''' | |
ryJim001.py | |
今天我要做的是, | |
從__(A)到_(B)_整數中,__(C)的倍數共有幾個。 | |
Renyuan Lyu , 2016/03/27 | |
''' | |
def 從a到b整數中c的倍數共有幾個(a, b, c): | |
''' | |
本函數 需輸入 a, b, c. | |
分別是 | |
較小的整數 a, | |
較大的整數 b, | |
以及 取倍數的對象 c | |
''' | |
if a>b: | |
print(' a > b, 你的輸入可能有誤!') | |
return 0 | |
x= 小於或等於a的c的倍數的個數= (a-1)//c | |
y= 小於或等於b的c的倍數的個數= b//c | |
z= 介於ab之間c的倍數的個數= y-x | |
return z | |
def main(): | |
''' | |
這是程式流程,控制使用者介面。 | |
''' | |
print('請輸入 a, b, c.') | |
a= int(input('a=? ')) | |
b= int(input('b=? ')) | |
c= int(input('c=? ')) | |
n= 從a到b整數中c的倍數共有幾個(a, b, c) | |
結果報告= '結果報告: 從 {} 到 {} 整數中 {} 的倍數共有 {} 個。'.format(a,b,c,n) | |
print(結果報告) | |
# 真正執行在此。 | |
main() | |
#---------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment