當前位置:成語大全網 - 新華字典 - Python題目

Python題目

#輸出"Hello,world!"

print('hello,world')

#從鍵盤輸入4個整數a,b,c,x計算函數值

a?=?int(input('請輸入a的值:'))

b?=?int(input('請輸入b的值:'))

c?=?int(input('請輸入c的值:'))

x?=?int(input('請輸入x的值:'))

y?=?(a*x)^?2?+?b*x+c

print('最終的值為:%s'%?y)

#計算費波納契數列的第?n?項的遞歸程序

def?fibonacci(n):

if?n?==?0?or?n?==1:

return?n

else:

return?fibonacci(n-1)?+?fibonacci(n-2)

print(fibonacci(3))

#從鍵盤輸入若幹個用空格分開的單詞,按字典序排序後輸出

inputWords?=?input('請輸入幾個單詞,用空格分開\n')

word?=?sorted(inputWords.split('?'))

print(word)