python 条件,循环

一些例子

#!/usr/bin/python
#!/usr/bin/env python3

print "-----------if application--------"
flag = False
name = 'UMR'
if name == 'xiaomai':
    print welcome xiaomai'
    flag = True
else:
    print name

print "-----------while application"
numbers = [12,13,14,15,16,17,57]
while len(numbers) > 0:
    number = numbers.pop()
    if (number % 2 ==0):
        print number
    else:
        print "that is odd number"

print "-----------for application-----------"
print "eg of 'for'1"
for letter in 'python':
    print 'Letter\n', letter
fruits = ['a','b','c']
for fruit in fruits:
    print fruit

print("eg of for 2")

idol = ['UMR1','UMR2','UMR3','UMR4']
i=0
for index in range(len(idol)):
    print(idol[i]+"is the best idol")
    i=i+1
print "-----------rock, paper, scissors------"
import random
start = raw_input('Are you ready for the game? Y/N')
while (start == 'Y'):
    print 'okay lets begin'
    s = int(random.randint(1,3))
    if s == 1:
        ind = 'rock'
    elif s == 2:
        ind = 'paper'
    elif s == 3:
        ind = 'scissors'
    m = raw_input('Input rock/paper/scissors or endgame')
    if (m == ind):
        print 'this is a tie'
    elif (m == 'paper'and ind == 'rock') or (m == 'rock' and ind == 'scissors') or (m == 'scissors' and ind == 'paper'):
        print 'congraduations you win '
    elif (m == 'rock'and ind == 'paper') or (m == 'paper' and ind == 'scissors') or (m == 'scissors' and ind == 'rock'):
        print 'what a pity, try again'
    elif (m == 'endgame'):
        break
    else :
        print 'Please input rock/paper/scissors or endgame'

print('-------BMI index------')
height=float(input('Please input your height(cm):  '))
weight=float(input('Please input your weight(kg):  '))
BMI=height/weight**2
if BMI<18.5:
    print('too light')
else:
    print('too heavy')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值