因本人刚开始写博客,学识经验有限,如有不正之处望读者指正,不胜感激;也望借此平台留下学习笔记以温故而知新。这一篇文章主要是最近阅读学习的书籍,算法都比较基础,可用于新手练习感觉。
《Python100经典练习题》百度网盘链接:
https://pan.baidu.com/s/1K2HHYpiRddGFhvd96sIj1Q
提取码:5hax
推荐指数:4颗星
附相关练习代码:
前50道(因该书也针对C和C++练习,所以有的要求python中无法实现,只能跳过)
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
'''
1.
s = 0
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if (i!=j) and (i!=k) and (j!=k):
num = 100*i+j*10+k
print(num)
s+=1
print(s)
'''
'''
2.
I = int(input())
i1 = 10*10/100
i2 = i1+10*7.5/100
i4 = i2+20*5/100
i6 = i4+20*3/100
i10 = i6+40*1.5/100
if I<10:
interest = I*10/100
elif I<20:
interest = i1+(I-10)*7.5/100
elif I<40:
interest = i2+(I-20)*5/100
elif I<60:
interest = i4+(I-40)*3/100
elif I<100:
interest = i6+(I-60)*1.5/100
else:
interest = i10+(I-100)*1/100
print (interest)
'''
'''
3.
import math
for i in range(10000):
x = int(math.sqrt(i+100))
y = int(math.sqrt(i+268))
if (x*x==i+100) and (y*y==i+268):
print(i)
'''
'''
4.
date = input().split()
year = int(date[0])
month = int(date[1])
day = int(date[2])
mon_1 = 31
if year/4==0:
mon_2 = mon_1+29
else:
mon_2 = mon_1+28
mon_3 = mon_2+31
mon_4 = mon_3+30
mon_5 = mon_4+31
mon_6 = mon_5+30
mon_7 = mon_6+31
mon_8 = mon_7+31
mon_9 = mon_8+30
mon_10 = mon_9+31
mon_11 = mon_10+30
if month==1:
days = day
elif month==2:
days = mon_1+day
elif month==3:
days = mon_2+day
elif month==4:
days = mon_3+day
elif month==5:
days = mon_4+day
elif month==6:
days = mon_5+day
elif month==7:
days = mon_6+day
elif month==8:
days = mon_7+day
elif month==9:
days = mon_8+day
elif month==10:
days = mon_9+day
elif month==11:
days = mon_10+day
else:
days = mon_11+day
print(days)
'''
'''
5.
x = int(input())
y = int(input())
z = int(input())
list = [x,y,z]
list.sort()
print(list)
'''
'''
6.
print('*'*10)
for i in range(5):
print('* *')
print('*'*10)
print('*\n'*6)
'''
'''
8.
for i in range(1,10):
for j in range(1,10):
print('%d X %d = %d ' %(i,j,i*j))
'''
'''
9.
for i in range(1,10):
for j in range(1,10):
result = i*j
print('%d*%d=%-3d'%(i,j,result))
print('')
'''
'''
10.
import sys
for i in range(8):
for j in range(8):
if(i+j)%2==0:
sys.stdout.write(chr(220))
sys.stdout.write(chr(219))
else:
sys.stdout.write(' ')
print(' ')
'''
'''
10.
import sys
sys.stdout.write(chr(1))
sys.stdout.write(chr(1))
print('')
for i in range(1,11):
for j in range(1,i):
sys.stdout.write(chr(219))
sys.stdout.write(chr(219))
print('')
'''
'''
11.
s = 0
def fac(a,b):
sum = a+b
print(a)
a = b
b = sum
if b<100:
fac(a,b)
fac(1,1)
'''
'''
12.
import math
for i in range(101,201):
end = math.floor(math.sqrt(i))
for j in range(2,end):
# print(j)
if i%j==0:
break
else:
print(i)
'''
'''
13.
for i in range(100,1000):
high = int(i/100)
mid = int((i/10)%10)
low = int(i%10)
if i==high**3+mid**3+low**3:
print(i)
'''
'''
14.
from sys import stdout
n = int(input())
for i in range(2,n):
if n%i==0:
stdout.write(str(i))
stdout.write('*')
n = n/i
else:
break
print(n)
'''
'''
17.
str = input()
letter = 0
space = 0
num = 0
others = 0
for c in str:
if c.isalpha():
letter+=1
elif c.isspace():
space+=1
elif c.isdigit():
num+=1
else:
others+=1
print('letters=%s,space=%s,num=%s,others=%s'%
(letter,space,num,others))
'''
'''
18.
a = int(input())
n = int(input())
s = [a]
aa = a
for i in range(1,n):
aa = a*(10**i)+aa
s.append(aa)
print(s)
print(sum(s))
'''
'''
19.
for i in range(1,1000):
l = []
for j in range(1,i):
if i%j==0:
l.append(j)
if i==sum(l):
print(i)
'''
'''
20.
high = 100
sum = high
for i in range(1,11):
high = high/2
sum += 2*high
print('Total distance:%s,High:%s'%(sum,high))
'''
'''
21.
sum = 1
for i in range(1,10):
sum = (sum+1)*2
print(sum)
'''
'''
22.
for i in range(ord('x'),ord('z')+1):
for j in range(ord('x'),ord('z')+1):
if i!=j:
for k in range(ord('x'),ord('z')+1):
if (i!=k) and(j!=k):
if (i!=ord('x'))and(k!=ord('x'))and(k!=ord('z')):
print('a-%s,b-%s,c-%s'%(chr(i),chr(j),chr(k)))
'''
'''
23.
s = '*'
for i in range(1, 8, 2):
print((s*i).center(7))
for i in reversed(range(1, 6, 2)):
print((s*i).center(7))
'''
'''
24.
num = 2
den = 1
sum = 0
for i in range(20):
sum+=(num/den)
num,den = num+den,num
print(sum)
'''
'''
25.
sum = 0
a = 1
for i in range(1,21):
pro = i*a
a = pro
sum+=pro
print(sum)
'''
'''
26.
def fac(i):
if i==0:
return 1
else:
return i*fac(i-1)
print(fac(5))
'''
'''
27.
def reverse(n):
next = 0
if n<=1:
next = input()
print (next)
else:
next = input()
reverse(n-1)
print(next)
reverse(5)
'''
'''
28.
i = 10
s = i
for j in range(2,6):
s+=2
print(s)
'''
'''
28.
def age(n):
if n==1:
c = 10
else:
c = age(n-1)+2
return c
print(age(5))
'''
'''
29.
x = int(input('input a number:\n'))
n5 = int(x/10000)
n4 = int(x%10000/1000)
n3 = int(x%1000/100)
n2 = int(x%100/10)
n1 = int(x%10)
if n5!=0:
print('there are %s nums'%(5),n5,n4,n3,n2,n1)
else:
if n4!=0:
print('there are %s nums'%(4),n4,n3,n2,n1)
else:
if n3!=0:
print('there are %s nums'%(3),n3,n2,n1)
else:
if n2!=0:
print('there are %s nums'%(2),n2,n1)
else:
print('there are %s nums'%(1),n1)
'''
'''
30.
x = int(input('input a number:\n'))
n5 = int(x/10000)
n4 = int(x%10000/1000)
n3 = int(x%1000/100)
n2 = int(x%100/10)
n1 = int(x%10)
if n1==n5 and n2==n4:
print('Yes')
else:
print('No')
'''
'''
31.
s = input('put a date:\n')
if s=='M':
print('星期一')
elif s=='T':
print('Not enough,put a next date:\n')
s1 = input()
if s1=='U':
print('星期二')
elif s1=='H':
print('星期四')
elif s=='W':
print('星期三')
elif s=='F':
print('星期五')
elif s=='S':
print('Not enough,put a next date:\n')
s1 = input()
if s1=='U':
print('星期日')
elif s1=='A':
print('星期六')
else:
print('不是星期的表示')
'''
'''
33.
import os
os.system('cls')
'''
'''
34.
def hello_word():
print('hello world')
def three_hellos():
for i in range(3):
hello_word()
if __name__=='__main__':
three_hellos()
'''
'''
37.
print('put in ten nums:\n')
N = 10
l = []
for i in range(10):
a = input('')
l.append(a)
for i in range(N-1):
min = i
for j in range(i+1,N):
if l[min]>l[j]:
min=j
l[i],l[min]=l[min],l[i]
for i in range(N):
print(l[i])
'''
'''
38.
print('put in a num:\n')
a = []
sum = 0
for i in range(3):
a.append([])
for j in range(3):
a[i].append(int(input()))
print(a)
for i in range(3):
sum+=a[i][i]
print(sum)
'''
'''
39.
if __name__=='__main__':
a = [1,2,4,6,8,10,12,13,14,15]
num = int(input())
if num>a[len(a)-1]:
a.append(num)
else:
for i in range(len(a)):
if a[i]>num:
a.insert(i,num)
break
print(a)
'''
'''
40.
if __name__=='__main__':
a = [1,2,3,4,5]
for i in range(int(len(a)/2)):
a[i],a[len(a)-1-i]=a[len(a)-1-i],a[i]
print(a)
'''
'''
50.
maxing = lambda x,y:(x>y)*x+(x