请问有会用Python编程语言编几个小程序的吗?谢谢题目如下。

1、连续整数之和:写一个程序,提示输入变量x,然后计算从1开始连续x个整数之和。例如,如果X是5,则计算1+2+3+4+5=15。2、连续整数之和改进版:写一个程序,提示... 1、连续整数之和:写一个程序,提示输入变量x,然后计算从1开始连续x个整数之和。例如,如果X是5,则计算1+2+3+4+5=15。
2、连续整数之和改进版:写一个程序,提示输入变量x,然后计算从1开始连续x个整数之和。示例如下,例如,如果X是5,则
1
=1
1+2
=3
1+2+3
=6
1+2+3+4
=10
3、算数游戏:编写一小程序,要求输入行数,则完成如下功能
1*8+1=9
12*8+2=98
123*8+3=987
1234*8+4=9876
12345*8+5=98765
4、算数游戏:编写一小程序,要求输入行数,则完成如下功能
1*9+2=11
12*9+3=111
123*9+4=1111
1234*9+5=11111
12345*9+6=111111
展开
 我来答
花花浪客
2013-05-23 · TA获得超过2069个赞
知道小有建树答主
回答量:792
采纳率:100%
帮助的人:711万
展开全部

题目1

if __name__ == '__main__':
    number = input("Please input a number:")
    number = int(number)
                                                                                
    i = 1
    sum = 0
    output = ""
    while i <= number:
        sum = sum + i
        if i == 1:
            output = "1"
        else:
            output = "%s+%d"%(output, i)
        i = i + 1
    print("Result: %s=%d"%(output, sum))

运行结果


题目2

if __name__ == '__main__':
    number = input("Please input a number:")
    number = int(number)
                                                
    i = 1
    while i <= number:
        sum = 0
        j = 1
        output = ""
        while j <= i:
            sum = sum + j
            if j == 1:
                output = "1"
            else:
                output = "%s+%d"%(output, j)
            j = j + 1
                                            
        print("%s=%d"%(output, sum))
        i = i + 1

运行结果

题目3

if __name__ == '__main__':
    number = input("Please input a number:")
    number = int(number)
                                     
    i = 1
    while i <= number:
        num = 0
        j = 1
        while j <= i:
            num = num * 10 + j
            j=j+1
                                     
        sum = num*8 + i
        print("%d*8+%d=%d"%(num,i, sum))
        i = i + 1

运行结果

题目4

if __name__ == '__main__':
    number = input("Please input a number:")
    number = int(number)
                          
    i = 1
    while i <= number:
        num = 0
        j = 1
        while j <= i:
            num = num * 10 + j
            j=j+1
                          
        sum = num*9 + (i+1)
        print("%d*9+%d=%d"%(num,i+1, sum))
        i = i + 1

运行结果

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式