python 条件,循环

xiaoxiao2021-02-28  135

一些例子

#!/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')
转载请注明原文地址: https://www.6miu.com/read-39433.html

最新回复(0)