起因
辦公室里同事都是女的佃牛,所以換桶裝水的健身活動,只能由我一個人干了床未。換水回來竭翠,猛地一想,這活如果編碼該怎么搞呀薇搁。
環(huán)境
換水的地方在一個會議室斋扰,如果有會議還不能換
目的
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()
經(jīng)驗總結(jié)
Python的編碼縮進很重要,這是程序識別代碼塊的重要依據(jù)