python 在一個(gè)范圍內(nèi),尋找另一個(gè)數(shù)字的所有整數(shù)倍數(shù),并計(jì)算一共有多少個(gè)倍數(shù)
python 在一個(gè)范圍內(nèi),尋找另一個(gè)數(shù)字的所有整數(shù)倍數(shù),并計(jì)算一共有多少個(gè)倍數(shù)
這個(gè)是問題,真心不會(huì)做.我用的是python 2.7.要用 for loop
1) 建立程序 count_multiples() which takes 三個(gè)非負(fù)整數(shù):base,start and stop,prints each integer multiple of base which
occurs between start and stop (including start but not including stop) on a separate line,
and returns the number of multiples found.假如 base = 3,那在start = 9 和stop = 15之間就有2個(gè)整倍數(shù),9 和 12,但不包括15.the easiest way to test whether one number is an integer multiple of another is with the % operator.
\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05
\x05\x05\x05\x05
\x05\x05\x05
\x05\x05
\x05\x05\x05
\x05\x05\x05\x05
\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05
2).Write a function user_input_multiples() which takes a single integer input base.This
function will get start and stop values from the user with two calls to raw_input(),call
count_multiples() to determine the number of integer multiples of base between the user
specified start and stop,and then ask again for new start and stop values.The function will
continue asking for new start and stop values until at least one of the following cases occurs:
\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05\x05
The user enters a negative value for start or stop.
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05\x05
The user enters a value for stop which is less than the value for start.
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05\x05
The function count_multiples() returns zero (eg:there were no multiples between start and stop).
Once the function stops asking for input,it will return the total number of multiples found (the total
over all calls to count_multiples()).Hint:You will
want to use a while loop for this function.
英語有點(diǎn)多,看著有點(diǎn)煩,請(qǐng)見諒.第一部分我已經(jīng)盡量翻譯最主要的舉例了.
如果沒有時(shí)間,給我一個(gè)詳細(xì)的思路或者方向也行.:)
這個(gè)是問題,真心不會(huì)做.我用的是python 2.7.要用 for loop
1) 建立程序 count_multiples() which takes 三個(gè)非負(fù)整數(shù):base,start and stop,prints each integer multiple of base which
occurs between start and stop (including start but not including stop) on a separate line,
and returns the number of multiples found.假如 base = 3,那在start = 9 和stop = 15之間就有2個(gè)整倍數(shù),9 和 12,但不包括15.the easiest way to test whether one number is an integer multiple of another is with the % operator.
\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05
\x05\x05\x05\x05
\x05\x05\x05
\x05\x05
\x05\x05\x05
\x05\x05\x05\x05
\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05
2).Write a function user_input_multiples() which takes a single integer input base.This
function will get start and stop values from the user with two calls to raw_input(),call
count_multiples() to determine the number of integer multiples of base between the user
specified start and stop,and then ask again for new start and stop values.The function will
continue asking for new start and stop values until at least one of the following cases occurs:
\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05\x05
The user enters a negative value for start or stop.
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05\x05
The user enters a value for stop which is less than the value for start.
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05\x05\x05\x05\x05
The function count_multiples() returns zero (eg:there were no multiples between start and stop).
Once the function stops asking for input,it will return the total number of multiples found (the total
over all calls to count_multiples()).Hint:You will
want to use a while loop for this function.
英語有點(diǎn)多,看著有點(diǎn)煩,請(qǐng)見諒.第一部分我已經(jīng)盡量翻譯最主要的舉例了.
如果沒有時(shí)間,給我一個(gè)詳細(xì)的思路或者方向也行.:)
英語人氣:240 ℃時(shí)間:2019-10-19 21:33:14
優(yōu)質(zhì)解答
def count_multiples(base, start, stop): result=[] for item in range(start,stop): &n...
我來回答
類似推薦
- python里把1到123的數(shù)字中所有3的倍數(shù)換成A
- 從1~9這9個(gè)數(shù)碼中取出3個(gè),使他們的和是3的倍數(shù),有多少種取法?(最好有計(jì)算過程)謝謝了!
- VB編寫程序 計(jì)算1~100內(nèi)3的倍數(shù)的數(shù)的和
- 一個(gè)兩位數(shù)既是3的倍數(shù),又是5的倍數(shù),這個(gè)數(shù)最小是 (15)最大是(90).我想問過程是怎么算出來的.
- 在1-100這100個(gè)數(shù)中所有5的倍數(shù)之和是( 請(qǐng)列計(jì)算過程
- 四通八達(dá)中“達(dá)”什么意思
- 天地不仁,以萬物為芻狗.
- 用血球計(jì)數(shù)板計(jì)算酵母細(xì)胞總數(shù):對(duì)稀釋100倍后的酵母菌懸液計(jì)數(shù),若80小格中細(xì)胞數(shù)
- 富者乞羊 譯文
- 高中數(shù)學(xué)課程中的“函數(shù)”的結(jié)構(gòu)脈絡(luò)
- 描寫水的優(yōu)美句子
- 試證明:對(duì)于任意大于4的合數(shù)p,(p-2)!能被p整除.或舉出反例.
猜你喜歡
- 1世博會(huì)中國館的太陽能光伏發(fā)電系統(tǒng) 年均提供電能為1.08*10^13J,這意味著每年節(jié)約標(biāo)準(zhǔn)煤為( )噸(設(shè)標(biāo)準(zhǔn)煤完全燃燒,q煤=3.0*10^7J/kg)
- 2l理發(fā)師翻譯成英語
- 3在下列幾種現(xiàn)象中,系統(tǒng)動(dòng)量守恒的是
- 4王老師在新華書店購買了《童話精選》和《科學(xué)家的故事》一共花了116元,童話每本2
- 51 she also tried to teach him __ to be quiet because other people wanted to rest.A when B where
- 6求滿足條件:頂點(diǎn)在原點(diǎn),關(guān)于x軸對(duì)稱,并且經(jīng)過點(diǎn)M(2,-4)的拋物線的標(biāo)準(zhǔn)方程,并求出此拋物線的準(zhǔn)線方程.
- 7“鐵錘錘碗錘不碎”.這句話覺得荒謬的理由是什么?覺得有道理的理由是什么?
- 8如圖,已知直線L1平行L2,且L3和L1、L2分別交于A、B兩點(diǎn),點(diǎn)P在直線AB上.
- 9什么無間
- 10333分之33乘101怎樣簡便計(jì)算
- 11用總分總的形式寫一篇作文
- 121.What do you not like?還是What don't you like?Why do you not like?還是Why don't you like?