您的位置:首页 > 编程语言

2018.3.19 高级编程作业

2018-03-19 08:35 337 查看
5-2    更多的条件测试
str1='I am your father.'
>>> str2='I will buy some orange for you.'
>>> str1==str2
False
>>> str3='i am your father.'
>>> str1==str3
False
>>> str1.lower()==str3
True
>>>
>>> num1=546784522
>>> num2=546782453
>>> num1==num2
False
>>> num1!=num2
True
>>> num1>num2
True
>>> num1>=num2
True
>>>
>>> num3=6854754452
>>> num1>num3 and num1>num2
False
>>> num1>num3 or num1>num2
True
>>>
>>> 31 in cube
False
>>> 64 in cube
True

>>>
5-5    外星人颜色#3
alien_colors=['green','yellow','red']
for alien_color in alien_colors:
if alien_color=='green':
print('You got 5 points')
elif alien_color=='yellow':
print('You got 10 points')
else:
print('You got 15 points')

5-7    喜欢的水果
favorite_fruits=['apple','pear','tomato']
if('apple' in favorite_fruits):
print("You really like apple")
if('banana' in favorite_fruits):
print("You really like banana")
if('watermelon' in favorite_fruits):
print("You really like watermelon")
if('grape' in favorite_fruits):
print("You really like grape")
if('tomato' in favorite_fruits):

print("You really like tomato")

5-8 5-9   以特殊方式跟管理与打招呼 并处理没有用户的情形
usr=[]
if not usr:
print('We need to find some users!')
usr=['admin','Eric','Kevin','Julia','Rain']
for u in usr:
if u=='admin':
print('Hello admin,would you like to see a status report?')
else :
print('Hello '+u+',thank you for logging in again')

5-11    序数
num=list(range(1,10))
for n in num:
if n==1:
print('1st')
elif n==2:
print('2nd')
elif n==3:
print('3rd')
else:
print(str(n)+'th')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: