5-3到5-5
#5-3 alien_color='green' if alien_color=='green': print('you got five points!') alien_color='red' if alien_color=='green': print('you got five points!') #5-4 alien_color='red' if alien_color=='green': print('you got five points!') else: print('you got ten points') alien_color='green' if alien_color=='green': print('you got five points!') else: print('you got ten points') #5-5 alien_color='green' if alien_color=='green': print('you got five point') elif alien_color=='red': print('you got ten point!') else: print('you got fifteen points!') alien_color='red' if alien_color=='green': print('you got five point') elif alien_color=='red': print('you got ten point!') else: print('you got fifteen points!') alien_color = 'yellow' if alien_color == 'green': print('you got five point') elif alien_color == 'red': print('you got ten point!') else: print('you got fifteen points!')
结果:
you got five points!
you got ten points
you got five points!
you got five point
you got ten point!
you got fifteen points!
本文通过Python代码展示了不同颜色的外星人被击中时玩家得分的变化情况。使用了简单的if-else及if-elif-else结构来实现条件判断,并根据外星人的颜色输出不同的得分结果。
1645

被折叠的 条评论
为什么被折叠?



