python编程从入门到实践第五章习题
2018-03-20 21:42
453 查看
#5.2
#5.3-5.5
#5.6
#5.11
cars = [ 'bwm' , 'audi' , 'subaru' ] a_str = 'BWM' print( a_str == cars[0] ) print( a_str.lower() == cars[0] ) print( a_str.lower() in cars ) print( a_str.lower() not in cars )
#5.3-5.5
#5.3 alien_color = 'green' if alien_color == 'green' : print( "The player gets five points" ) if alien_color == 'red' : print( "The color is red" ) #5.4 if alien_color == 'green': print( "The player gets five points" ) else: print( "The player gets ten points") #5.5 if ( alien_color == 'green' ): print( "The player gets five points" ) elif ( alien_color == 'red' ) : print( "The player gets ten points" ) elif ( alien_color == 'yellow' ) : print( "The player gets fifteen points" )
#5.6
age = input("please input your age\n") age = int(age) if age < 2 : print( "婴儿") elif age < 4 : print( "你在蹒跚学步") elif age < 13 : print( "儿童") elif age < 20 : print( "青少年") elif age < 65 : print("成年人") else: print("90后老年人")#5.7
favorite_fruits = ['apple' , 'banana' , 'orange' ] fruits = [ 'apple' , 'pineapple' , 'banana' , 'pitaya', 'orange' ] for fruit in fruits: if fruit in favorite_fruits: print( "you really like " + fruit ) else : print( "you don't like " + fruit)#5.8-5.9
names = ['admin' , 'a' , 'b' , 'c' ,'d' ] for ele in names : if ele == 'admin' : print( "Hello admin, would you like to see a status report?" ) else : print ("hello "+ele+", thank you for logging in again" ) if names.size() == 0 : print( "We need to find some ueser!")#5.10
current_users = ['a' ,'b' , 'c','d','e'] new_users = ['a' , 'adf' ,'B','fds' , 'lizhch'] for name in new_users : flag = 1 for ele in current_users: if name.lower() == ele.lower() : print( "Please input another user name" ) flag = 0 if flag : print( "It can be used" )
#5.11
nums = [ i for i in range(1,10) ] for ele in nums : if ele == 1 : print( str(ele) + "st") elif ele == 2 : print( str(ele) + "nd" ) elif ele == 3 : print( str(ele) + "rd" ) else : print( str(ele) + "th" )
相关文章推荐
- Python编程:从入门到实践 第五章习题解析
- 【《Python编程: 从入门到实践》习题答案--第五章:<if语句>】
- 《Python编程 从入门到实践》第五章课后习题
- 《Python编程 从入门到实践》第五章习题选做
- 《Python编程——从入门到实践》第五章部分习题解
- 《Python编程-从入门到实践》第2章习题选练
- 《python编程从入门到实践》 第2章习题选做
- Python编程 从入门到实践 部分习题解答 第二章
- 《Python编程 从入门到实践》第三章习题选做
- Python编程:从入门到实践(课后习题10)
- 【《Python编程: 从入门到实践》习题答案--第四章:<list 列表操作>】
- 《Python编程 从入门到实践》第七章习题选做
- 《Python编程——从入门到实践》第三章部分习题解
- 《Python编程-从入门到实践》课后习题(5)
- 《Python编程 从入门到实践》第六章课后习题
- 《Python编程-从入门到实践》课后习题(6)
- python编程:从入门到实践 第九章习题
- 《Python编程 从入门到实践》第三章课后习题
- 《Python编程 从入门到实践》第四章课后习题
- 《Python编程-从入门到实践》第5、6章习题选练