python123数值运算答案_python在一个范围内,寻找另一个数字的所有整数倍数,并计算一共有多少个倍数这个是问题,真心不会做.我用的是python2.7.要用forloop1)建立程序coun...

python 在一个范围内,寻找另一个数字的所有整数倍数,并计算一共有多少个倍数

这个是问题,真心不会做.我用的是python 2.7.要用 for loop

1) 建立程序 count_multiples() which takes 三个非负整数: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个整倍数,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.

英语有点多,看着有点烦,请见谅.第一部分我已经尽量翻译最主要的举例了.

如果没有时间,给我一个详细的思路或者方向也行.:)

英语作业帮用户2016-12-05举报

icon_report_d51b383.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值