TQC+ 程式語言 Python 3 _ 703 數組條件判斷

說明:
請撰寫一程式,輸入一些字串至數組(至少輸入五個字串),以字串"end"為結束點(數組中不包含字串"end")。接著輸出該數組,再分別顯示該數組的第一個元素到第三個元素和倒數三個元素。
範例輸入:
president
dean
chair
staff
teacher
student
end
範例輸出:
('president', 'dean', 'chair', 'staff', 'teacher', 'student')
('president', 'dean', 'chair')
('staff', 'teacher', 'student')
程式碼:
strLi,str1 = [],input()

while str1 != "end":
    strLi.append( str1 )
    str1 = input()

strTup = tuple( strLi )

print( strTup )
print( strTup[0:3] )
print( strTup[-3:] )

沒有留言:

張貼留言