python计算m的n次幂代码_在Python程序中计算n + nn + nnn +…+ n(m次)

我们将编写一个程序,用Python计算以下系列。检查我们要编写的程序的示例输入和输出。Input:

34

3 + 33 + 333 + 3333

Output:

3702

Input:

5 5 5 + 55 + 555 + 5555 + 55555

Output:

61725

因此,我们将有两个数字,并且我们必须计算如上 生成的序列之和。请按照以下步骤实现输出。

算法1. Initialize the number let's say n and m.

2. Initialize a variable with the value n let's say change.

3. Intialize a variable s to zero.

4. Write a loop which iterates m times.

4.1. Add change to the s.

4.2. Update the value of change to get next number in the series.

5. Print the sum at the end of the program.

您必须创建一个通用公式来生成系列中的数字。尝试将其作为自己的。如果您坚持逻辑,请参见下面的代码。

示例## intializing n and m

n, m = 3, 4

## initializing change variable to n

change = n

## initializing sum to 0

s = 0

## loop<

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值