Skip to content

Instantly share code, notes, and snippets.

@renyuanL
Created March 26, 2016 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renyuanL/7af1a2800f10a9f43e22 to your computer and use it in GitHub Desktop.
Save renyuanL/7af1a2800f10a9f43e22 to your computer and use it in GitHub Desktop.
solving a math problem for Jimmy
#----------------------------------------------
'''
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