脚本集合

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)
 

转载于:https://www.cnblogs.com/andychen520/p/8977592.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值