脚本集合

1、0-100之和
(1)
#!/usr/bin/env python
# -*- coding:utf8 -*-
# Author:Andy Chen 2018/5/1

total = 0

for i in range(101):
total = total + i
print(total)
(2)
n = 0
s = 1

while True:
n = n + s
if s == 100:
break
s += 1
print(n)
2、随机数
(1)
#!/usr/bin/env python  
# -*- coding:utf8 -*-
# Author:Andy Chen

import random

for i in range(5):
print(random.randint(1,10))
(2)
#!/usr/bin/env python  
# -*- coding:utf8 -*-
# Author:Andy Chen

import random

messages = ['It is ce[rtain',
'It is decidedly so',
'Yes definitely',
'Reply hazy try again',
'Ask again later',
'Concentrate and ask again',
'My reply is no',
'Outlook not so good',
'Very doubtful']
print(messages[random.randint(0, len(messages) - 1)])
3、使用while循环输出 1 2 3 4 5 6   8 9 10
# !/usr/bin/env python
# -*- conding: utf-8 -*-
# Author:jack chen 2018/04/29

count = 0

while count <10:
count += 1
if count == 7:
continue
print(count)
print("end")
4、输出 1-100 内的所有偶数
sum = 0
for a in range(1,101):
if a%2 ==0:
continue
else:
sum = sum + a
print(sum)
5、输出 1-100 内的所有奇数
sum = 0
# 开始循环
for count in range(1, 101):
if count % 2 == 1:
sum += count
print(sum)
 
posted @ 2018-05-01 21:36  十八哥andy  阅读(324)  评论(0编辑  收藏  举报