題目: 请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。
http://www.runoob.com/python/python-exercise-example31.html
My code:
print ("Key in letter to search week day\n")
i=0
weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Satursday"]
while len(weekdays)>1:
user_input = input("Input:")
j=len(weekdays)-1
while j>=0:
#print (weekdays[j][i])
if (weekdays[j][i] != user_input):
weekdays.pop(j)
j=j-1
i = i+1
print (weekdays)
沒有留言:
張貼留言
Thanks for your message.