1、if语句的练习
cars=['aodi','bmw','falali','lanbojini'] for car in cars: if car == 'bmw': print(car.upper()) else: print(car.lower())
2、外星人颜色的练习
alien_color=['green','yellow','red'] if alien_color =='green': count =5 if alien_color=='yellow': count=10 if alien_color=='red': count=15 print(' the player get %d point!'%count)
3、游乐场收费的练习
age=int(input()) if age<4: price =0 elif 4<=age<18: price =5 else: price =10 print('shoufei: %d元'%price)
4、是否在列表中
a1=[1,2,3,4,5]
a2=9
if a2 in a1:
print('in list')
else:
print('not in list !')
5、序数
#序数表示位置,如1st 和2nd。大多数序数都以th结尾,只有1、2和3例外。 #在一个列表中存储数字1~9。 #遍历这个列表。 #在循环中使用一个if-elif-else 结构,以打印每个数字对应的序数。 # 输出内容应为1st、2nd、3rd、4th、5th、6th、7th、8th 和9th,但每个序数都独占一 行。 a=[] for i in range(1,10): a.append(i) for b in a: if b ==1: print(str(b)+'st') elif b==2: print(str(b)+'nd') elif b==3: print(str(b) + 'rd') else: print(str(b) + 'th')