python 条件,循环

来源:互联网 发布:正规矩阵奇异值 编辑:程序博客网 时间:2024/06/03 22:55

一些例子

#!/usr/bin/python#!/usr/bin/env python3print "-----------if application--------"flag = Falsename = 'UMR'if name == 'xiaomai':    print welcome xiaomai'    flag = Trueelse:    print nameprint "-----------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', letterfruits = ['a','b','c']for fruit in fruits:    print fruitprint("eg of for 2")idol = ['UMR1','UMR2','UMR3','UMR4']i=0for index in range(len(idol)):    print(idol[i]+"is the best idol")    i=i+1print "-----------rock, paper, scissors------"import randomstart = 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**2if BMI<18.5:    print('too light')else:    print('too heavy')
原创粉丝点击