python 练习

!/usr/bin/python

-- coding: UTF-8 --

for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if( i != k ) and (i != j) and (j != k):
print i,j,k

!/usr/bin/python

coding=utf-8

year=int(raw_input('year:\n'))
month = int(raw_input('month:\n'))
day = int(raw_input('day:\n'))

!/usr/bin/python

-- coding: UTF-8 --

year = int(raw_input('year:\n'))
month = int(raw_input('month:\n'))
day = int(raw_input('day:\n'))

months = (0,31,59,90,120,151,181,212,243,273,304,334)
if 0 < month <= 12:
sum = months[month - 1]
else:
print 'data error'
sum += day
leap = 0
if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
leap = 1
if (leap == 1) and (month > 2):
sum += 1
print 'it is the %dth day.' % sum

!/usr/bin/python

-- coding: UTF-8 --

l = []
for i in range(3):
x = int(raw_input('integer:\n'))
l.append(x)
l.sort()
print l

!/usr/bin/python

-- coding: UTF-8 --

def fib(n):
a,b = 1,1
for i in range(n-1):
a,b = b,a+b
return a

输出了第10个斐波那契数列

print fib(10)

列表复制

!/usr/bin/python

-- coding: UTF-8 --

a = [1, 2, 3]
b = a[:]
print b

!/usr/bin/python

-- coding: UTF-8 --

for i in range(1, 10):
print
for j in range(1, i+1):
print "%d%d=%d" % (i, j, ij),

time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))

!/usr/bin/python

-- coding: UTF-8 --

for n in range(100,1000):
i = n / 100
j = n / 10 % 10
k = n % 10
if n == i ** 3 + j ** 3 + k ** 3:
print n

!/usr/bin/python

-- coding: UTF-8 --

import datetime

if name == 'main':

# 输出今日日期,格式为 dd/mm/yyyy。更多选项可以查看 strftime() 方法
print(datetime.date.today().strftime('%d/%m/%Y'))

# 创建日期对象
miyazakiBirthDate = datetime.date(1941, 1, 5)

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'))

你可能感兴趣的:(python 练习)