起因
办公室里同事都是女的,所以换桶装水的健身活动,只能由我一个人干了。换水回来,猛地一想,这活如果编码该怎么搞呀。
环境
换水的地方在一个会议室,如果有会议还不能换
目的
1.桶有水,不用换
2.桶空了,还有两种情况:
(1)会议室正在开会,不能换水
(2)会议室没人,可以换水
Python编码
buck_list = ['full','empty']
room_list = ['meeting','no meeting']
def buck_acount():
buck = input('The buck is:')
buck_full = buck == buck_list[0]
buck_empty = buck == buck_list[-1]
if buck_full:
print('You do not need to change water! You are free to do other things!')
elif buck_empty:
room = input('The room is:')
room_meeting = room == room_list[0]
room_nomeeting = room ==room_list[-1]
if room_meeting:
print('You cannot to change water!')
elif room_nomeeting:
print('You can change water!')
else:
print('Please input the right words, full or empty')
buck_acount()
buck_acount()
经验总结
Python的编码缩进很重要,这是程序识别代码块的重要依据