自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(51)
  • 收藏
  • 关注

原创 利用Python统计文本词频

#0705import csvpaper = str(input())paper = paper.lower()paper = paper.replace(',', ' ')paper = paper.replace('.', ' ')lst = []for i in paper.split(): lst.append(i)lst_set = set(lst)Dict = {}for item in lst_set: Dict.update({item: ls...

2022-04-29 00:20:46 212

原创 Python创建通讯录

#0704import csvn = int(input())row_list = [['姓名','联系电话']]for i in range(0,n): info = str(input()) lst = [] for j in info.split(' '): lst.append(j) row_list.append(lst)with open('Pyprog0704.csv', 'w', encoding='utf8' , newlin...

2022-04-29 00:00:38 252

原创 利用Python统计成绩

#0703LScore = int(input())UScore = int(input())import csvwith open('Pyprog0703.csv') as csvfile: reader = csv.reader(csvfile) rows = [row for row in reader]for lst in rows: a=0 for i in lst: try: i=int(i) ...

2022-04-28 23:49:32 271

原创 Python整除数据

#0702csv_file = open('Pyprog0702.csv')num=csv_file.read()csv_file.close()nList=[]for i in num.split(','): i=int(i) nList.append(i)n = int(input())for j in nList: if j%n==0: print(j,end=' ')

2022-04-28 23:30:41 104

原创 利用Python统计字母

#0701ch1 = str(input())ch2 = str(input())txt_file = open('Pyprog0701.txt','r')wrd = txt_file.read()wrd = wrd.lower()txt_file.close()m=0if ch1>ch2: max=ch1 min=ch2else: max=ch2 min=ch1for i in range(ord(min),ord(max)+1): ...

2022-04-28 23:27:06 264

原创 Python字典合并

#0608a = dict(eval(input()))b = dict(eval(input()))for k in b.keys(): a[k] = a.get(k, 0) + b[k]t = list(a.items())t.sort(key=lambda x : ord(x[0]) if type(x[0]) == str else x[0])c = str(dict(t)).replace(' ', '').replace("'", '"')print(c)

2022-04-22 01:07:51 100

原创 Python验证密码

#0607password_dict={'Jone':'abc','Mike':'123','Mary':'123456','Rose':'abc123','Tom':'123456'}id,password=map(str,input().split())if id in password_dict: if password==password_dict[id]: print('Successful login') else: print('Th...

2022-04-22 00:56:32 158

原创 随机字符列表排序

#0606import randomm=int(input())n=int(input())random.seed(m)lst1=[]for i in range(0,n): a=random.randint(0,9) lst1.append(a) lst2=list(set(lst1))lst3=[str(i) for i in lst2]print(lst3)

2022-04-22 00:53:49 85

原创 统计英文单词的个数

#0605lst0=input()lst0=lst0.replace(',',' ')lst0=lst0.replace('.',' ')lst1=[i for i in lst0.split()]lst2=[]for j in lst1: lst2.append(j.upper())lst3=list(set(lst2))num=len(lst3)print('There are {} words in the paragraph.'.format(num))

2022-04-22 00:47:05 106

原创 Python找中位数

#0604lst0=input()lst1=[int(j) for j in lst0.split(' ')]i=len(lst1)lst1.sort()if len(lst1)%2==0: a=lst1[(i//2)-1] b=lst1[(i//2)] c=float((a+b)/2)else: c=float(lst1[(i//2)])print(round(c,1))

2022-04-22 00:41:58 91

原创 Python列表排序

#0603lst0=input()lst1=[int(j) for j in lst0.split(' ')]i=int(input())del lst1[i]lst1.sort(reverse=True)print(lst1)

2022-04-22 00:18:17 80

原创 Python实现插入元素

#0602nList=eval(input())num=int(input())x=int(input())if num in nList: a=nList.index(num) nList.insert(a+1,x)else: nList.append(x)print(nList)

2022-04-22 00:13:32 82

原创 Python计算平均年龄

list=eval(input())num=len(list)/3age=0for i in list: if type(i)==int: age=age+iaverage_age=age/numprint('The average age of {} students is {}'.format(int(num),round(average_age,1)))

2022-04-22 00:06:20 501

原创 Python检测密码强度

s=str(input())a=0b=0c=0d=0e=0for i in range(0,len(s)): f=s[i] if s[i].isupper(): a=a+1 elif s[i].isdigit(): b=b+1 elif s[i].islower(): c=c+1 elif 32<=ord(s[i])<=47 or 58<=ord(s[i])<=64 or 91&...

2022-04-14 23:35:37 1569

原创 格式化输出

c=str(input())n=int(input())ymd=str(input())i=0while i<n-1: i=i+1 print(c,end='')print(c)ymd=ymd.split('/')print(ymd[0],end='')print('年',end='')if int(ymd[1])<10: print('0',end='') print(ymd[1],end='')else: print(y...

2022-04-14 23:30:31 80

原创 Python实现单词统计

s=str(input())s=s.replace(',',' ')s=s.replace('.',' ')s=s.replace('?',' ')s=s.replace('!',' ')s=s.split(' ')s1=[x for x in s if x!='']print(len(s1))

2022-04-14 23:20:31 524

原创 字符串加密

key=int(input())s=str(input())for i in range(0,len(s)): if 'a'<=s[i]<='z': print(chr( ord('a') + ((ord(s[i])-ord('a')) + key )%26 ),end='') elif 'A'<=s[i]<='Z': print(chr( ord('A') + ((ord(s[i])-ord('A')) + key )%26...

2022-04-14 23:14:43 56

原创 Python实现删除字符

s=str(input())new_s=[]for i in range(0,len(s)): if s[i].isdigit(): new_s.append(s[i]) print(s[i],end='')

2022-04-14 23:02:27 102

原创 Python提取身份证号信息

i=str(input())y=i[6:10]m=i[10:12]d=i[12:14]print(y,end='')print('年',end='')print(m,end='')print('月',end='')print(d,end='')print('日')x=int(i[16])if x%2==0: print('女')else: print('男')

2022-04-14 22:59:01 552

原创 Python查找字符

s=str(input())c=str(input())a=s.rindex(c)print('Index=',end='')print(a)b=s.count(c)print('Count=',end='')print(b)

2022-04-14 22:53:17 104

原创 Python实现取子串

s=str(input())m=eval(input())n=eval(input())print(s[m-1:n])

2022-04-14 22:48:24 176

原创 Ackermenn函数

​def Ack(m,n): if m==0: a=n+1 return a elif n==0 and m>0: a=Ack(m-1,1) return a elif m>0 and n>0: a=Ack(m-1,Ack(m,n-1)) return am,n=map(int, input().split( ))#######################...

2022-04-07 01:06:29 130

原创 Python实现可逆素数

def isPrime(x): for i in range(2,x): if x%i==0: return False return Truedef Reverse(x): x=str(x) a=x[::-1] b=int(a) return b#######################################m,n=map(int,input().split())for i in ra...

2022-04-07 00:58:03 466

原创 特殊a串数列和

def mySum(a,n): b=0 c=0 for i in range(1,n+1): b=a*(10**(i-1))+b c=c+b return c######################a=int(input())n=int(input())print(mySum(a,n))

2022-04-07 00:53:07 55

原创 一个月有几天

def isLeap(y): if y%4==0: return True else: return False####################a=int(input())#检验#print(isLeap(a))#######y=int(input())m=int(input())if m in (1,3,5,7,8,10,12): days=31elif m in (4,6,9,11): days=30else...

2022-04-07 00:47:32 59

原创 Python统计完全平方数

def isSquare(n): for i in range(1,n+1): if i**2==n: return 1 return 0###################m=int(input())n=int(input())c=0for i in range(m,n+1): if isSquare(i)==1: c=c+1print(c)

2022-04-07 00:38:53 354

原创 Python阶乘求和

def Fact(n): a=1 for i in range(1,n+1): a=a*i return am=int(input())c=0for j in range(1,m+1): b=Fact(j) c=c+pow(-1,j-1)*bprint(c)

2022-04-06 19:17:52 140

原创 Python最小公倍数

def Gcd(x,y): #判断两数是否相同 if x==y: return x #判断两数大小 if x>y: max=x min=y else: max=y min=x #辗转相除法 r=max%min while r!=0: max=min min=r r=max%min return mi...

2022-04-06 19:07:18 88

原创 Python求奇数和

def Even(x): if x%2==0: return True else: return Falsestrdata=input()oddsum=0for item in strdata.split(): i=int(item) if Even(i)==False: oddsum=oddsum+iprint(oddsum)

2022-04-06 16:11:10 429

原创 Python阶乘和数

n=eval(input())x=len(str(n))#判断位数num=1c=0b=1for i in range(1,x+1):#计算n的每位数 a=n//pow(10,x-i)%10 b=1 for j in range(1,a+1):#计算阶乘 b = b * j c=c+bif c==n:#比较累计阶乘与原数值 print('Yes')else: print('No')...

2022-03-29 17:16:00 519

原创 Python素数个数

m,n=eval(input())num=[]for i in range(m,n+1): for j in range(2,i): if i%j==0: break else: num.append(i)print(len(num))

2022-03-29 17:00:19 118

原创 求整数位及其各位数字之和

n=eval(input())x=len(str(n))c=0for i in range(0,x): a=str(n) b=int(a[i]) c=c+bprint('{} {}'.format(x,c))

2022-03-29 16:45:39 98

原创 Python最小公倍数

m,n=eval(input())x=1if m>n: max=m min=nelse: max=n min=mif max%min==0:#判断max是否为min的倍数 print(max)else: while (max*x)%min!=0:#循环求得最小公倍数 x=x+1 print(max*x)

2022-03-29 15:39:08 82

原创 Python前n项和

n=eval(input())a = 1b = 1d=1if n==1: print('{:.6f}'.format(1))else: for i in range(1,n): c = a+b a = b b = c d=d+pow(-1,i)*(i/c) print('{:.6f}'.format(d))

2022-03-29 15:12:42 573

原创 Python斐波那契数列

n = int(input())if n == 1: print(1)elif n == 2: print(1)else: a = 0 b = 1 for i in range(1,n): c = a+b a = b b = c print(c)

2022-03-29 14:26:03 162

原创 Python完数判断

n=eval(input())a=0for i in range(1,n,1): if n%i==0: a=a+iif a==n: print('Yes')else: print('No')

2022-03-28 11:27:46 936

原创 整数求和:输入一个正整数n,求解并输出1~n之间能被3整除、但不能被7整除的所有整数之和

n=eval(input())a=0for i in range(1,n+1,1): if i/3==i//3: if i/7!=i//7: a=a+iprint(a)

2022-03-28 11:21:19 1101

原创 输入3条线段长度,判断这3条线段构成的三角形类型。

a,b,c=eval(input())if a+b>c and a+c>b and b+c>a: if a==b==c: print('Equilateral Triangle') elif a==b or a==c or b==c: print('Isosceles Triangle') else: print('Scalene Triangle')else: print('No Triang...

2022-03-20 11:48:57 2395

原创 输入一个字符c,判断该字符是字母字符、数字字符还是其他字符,然后分别输出“Letter”、“Digit”或“Other”

c=input()if c.isalpha(): print('Letter')elif c.isdigit(): print('Digit')else: print('Other')

2022-03-20 11:34:09 2033

原创 根据输入的三角形的三条边a、b、c,如果可以构成三角形,计算并输出该三角形的面积和周长,否则输出“Not a Valid Triangle”。

a,b,c=eval(input())if a+b>c and a+c>b and b+c>a: p=(a+b+c)/2 S=pow(p*(p-a)*(p-b)*(p-c),1/2) C=a+b+c print('{:.2f} {:.2f}'.format(S,C))else: print('Not a Valid Triangle')

2022-03-20 11:22:31 5123

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除