码迷,mamicode.com
首页 > 编程语言 > 详细

Python开发【第一篇】基础题目

时间:2018-08-12 11:55:47      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:else   代码   span   style   range   ==   color   python   class   

1.求1-2+3-4+5.....99的所有数的和

n = 1
s = 0
while n<100:
    temp = n%2
    if temp == 0: #偶数
        s = s-n
    else:
        s = s+n
    n = n+1
print(s)

2.求1-100的所有数的和

n = 1
s = 0
while n < 101:
    s = s+n
    n = n+1
print(s)

#一行代码搞定
print (sum(range(101)))

3.九九乘法表

for i in range(1,10):
    for j in range(1,10):
        if i>=j:
            print("%s * %s == %s"%(j,i,i*j),end="\t")
    print("")

 

Python开发【第一篇】基础题目

标签:else   代码   span   style   range   ==   color   python   class   

原文地址:https://www.cnblogs.com/tangkaishou/p/9462166.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!