a = 2.0
b = 1.0
s = 0
for n in range(1,21):
s += a / b
t = a
a = a + b
b = t
print (s)
n = 0
s = 0
t = 1
for n in range(1,21):
t *= n
s += t
print ('1! + 2! + 3! + ... + 20! = %d' % s)
sum=0
def digui(n):
if n==0:
sum=1
else:
sum=n*digui(n-1)
return sum
print(digui(5))
def out(s,n):
if n == 0:
return
else:
print(s[n-1],end=' ')
out(s,n-1)
s=input('請輸入:')
#s=s.split(',')
n= len(s)
out(s,n)
def age(n):
if n == 1:
a=10
else:
a=age(n-1)+2
return a
print(age(5))
def jisuan(n):
l=while n!=0:
a=n%10
n=n//10
return l
n=int(input('請輸入:'))
l=jisuan(n)
a= len(l)
for i in range(a):
print(l[i],end=' ')
str=input('請輸入:')
a=int(str)
t=1for i in range(5//2):
if str[i] != str[5-i-1]:
t=0break
if t:
print('%d 是乙個回文數' % a)
else:
print('%d 不是乙個回文數' % a)
import datetime
if __name__ == '__main__':
# 輸出今日日期,格式為 dd/mm/yyyy。更多選項可以檢視 strftime() 方法
print(datetime.date.today().strftime('%d/%m/%y'))
# 建立日期物件
miyazakibirthdate = datetime.date(1998,3,18)
print(miyazakibirthdate.strftime('%d/%m/%y'))
# 日期算術運算
miyazakibirthnextday = miyazakibirthdate + datetime.timedelta(days=1)
print(miyazakibirthnextday.strftime('%d/%m/%y'))
# 日期替換
miyazakifirstbirthday = miyazakibirthdate.replace(year=miyazakibirthdate.year + 1)
print(miyazakifirstbirthday.strftime('%d/%m/%y'))
t=0
for i in range(ord('x'),ord('z') + 1):#a選手
for j in range(ord('x'),ord('z') + 1):#b選手
if i != j:
for k in range(ord('x'),ord('z') + 1):#c選手
if (i != ord('x')) and (k != ord('x')) and (k != ord('z')):#如果a不和x,c不和x和z
print('order is a -- %s\t b -- %s\tc -- %s' % (chr(i), chr(j), chr(k)))
t=1break
if t==1:
break
if t==1:
break
letter = input("please input:")
if letter == 's':
letter = input("please input second letter:")
if letter == 'a':
print('saturday')
elif letter == 'u':
print('sunday')
else:
print('data error')
elif letter == 'f':
print('friday')
elif letter == 'm':
print('monday')
elif letter == 't':
letter = input("please input second letter:")
if letter == 'u':
print('tuesday')
elif letter == 'h':
print('thursday')
else:
print('data error')
elif letter == 'w':
print('wednesday')
else:
print('data error')
Python經典基礎程式設計練習題(一) 每日10題
list1 count 0 for a in range 1,5 for b in range 1,5 for c in range 1,5 if a b and b c and a c d 100 a 10 b c count 1 print 一共有 d個三位數 count for i in li...
python 基礎練習題
學了這麼多天的python,也做了一點簡單的練習題,不過這點還不夠,要多做多敲 同樣也要學著理解,只有這樣才能才會進步小結1,怎樣做才能輸出列印乙個九九乘法表?如下 for i in range 1 10,1 for j in range 1 10,1 if j i print f end t pr...
Python 基礎練習題
以下是我在學習python編寫的一些簡單的練習題,題目答案為本人編寫可能不完全正確只供參考 列印乙個如下的圖形 for i in range 2,3 for z in range 3 abs i print end for j in range 2 abs i 1 print end print 輸...