当前位置: 首页 > news >正文

wordpress 移动站插件提高网站收录的方法

wordpress 移动站插件,提高网站收录的方法,信阳网站建设汉狮怎么样,网站建设及推广外包1.可否定义一个sum函数呢?返回指定区间的值的和?例如,区间[1,4]的和为123410返回指定区间值的平方的和呢?立方呢? 代码: # 计算从start到end(包括end)的所有整数的和。 def sum_ra…

1.可否定义一个sum函数呢?返回指定区间的值的和?例如,区间[1,4]的和为1+2+3+4=10返回指定区间值的平方的和呢?立方呢?

代码:

# 计算从start到end(包括end)的所有整数的和。
def sum_range(start, end):total = 0for i in range(start, end + 1):total += ireturn total
# 计算从start到end(包括end)的所有整数的平方和。
def sum_of_squares(start, end):total = 0for i in range(start, end + 1):total += i ** 2return total
# 计算从start到end(包括end)的所有整数的立方和。
def sum_of_cubes(start, end):total = 0for i in range(start, end + 1):total += i ** 3return total
# 计算区间[1, 4]的和
print("Sum of range [1, 4]:", sum_range(1, 4))  
# 计算区间[1, 4]的平方和
print("Sum of squares of range [1, 4]:", sum_of_squares(1, 4))  
# 计算区间[1, 4]的立方和
print("Sum of cubes of range [1, 4]:", sum_of_cubes(1, 4))

运行结果:

Sum of range [1, 4]: 10
Sum of squares of range [1, 4]: 30
Sum of cubes of range [1, 4]: 100

2.定义一个gcd函数,计算两个数的最大公因数

代码:

def gcd(a,b):while b:a,b=b,a%breturn a
print(gcd(28,12))

运行结果:

4

3.求出1-100之间的奇数之和

代码:

sumjs=0
for i in range(1,101):if(i%2!=0):sumjs+=i
print(sumjs)

运行结果:

2500

4.定义一个int类型变量接收一个大于100的三位数,求出100到该数字之间满足如下要求的数字之和:

1.数字的个位数不为7;
2.数字的十位数不为5;
3.数字的百位数不为3;
代码:

a=int(input("输入一个大于100的整数:"))
sum1=0
for i in range(100,a+1) :if(i%10!=7 and i//10%10!=5 and i//100!=3):sum1+=i
print(sum1)

运行结果:

输入一个大于100的整数:243
20900

5.有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?

代码:

def rabbit(n):if n==1 or n==2:return 1a,b=1,1for i in range(3,n+1):a,b=b,a+breturn b
for mon in range(1,13):print(f"第{mon}月的兔子总数为:{rabbit(mon)*2}")

运行结果:

1月的兔子总数为:22月的兔子总数为:23月的兔子总数为:44月的兔子总数为:65月的兔子总数为:106月的兔子总数为:167月的兔子总数为:268月的兔子总数为:429月的兔子总数为:6810月的兔子总数为:11011月的兔子总数为:17812月的兔子总数为:288

6.打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。

代码:

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

运行结果:
153
370
371
407

7.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

代码:

zm,kg,sz,others=0,0,0,0
str = input("请输入一行字符串:")
for char in str:if char.isalpha():zm += 1elif char.isspace():kg += 1elif char.isdigit():sz += 1else:others += 1
print("英文字母个数:", zm)
print("空格个数:", kg)
print("数字个数:", sz)
print("其它字符个数:", others)

运行结果:

请输入一行字符串:sekhhfk 4536!2#$%&^Gjhg^&
英文字母个数: 11
空格个数: 1
数字个数: 5
其它字符个数: 8

8.输出9*9口诀。

代码:

for i in range(1,10):for j in range(1,i+1):print(f"{j}*{i}={i*j}",end='\t')print()

运行结果:

1*1=1	
1*2=2	2*2=4	
1*3=3	2*3=6	3*3=9	
1*4=4	2*4=8	3*4=12	4*4=16	
1*5=5	2*5=10	3*5=15	4*5=20	5*5=25	
1*6=6	2*6=12	3*6=18	4*6=24	5*6=30	6*6=36	
1*7=7	2*7=14	3*7=21	4*7=28	5*7=35	6*7=42	7*7=49	
1*8=8	2*8=16	3*8=24	4*8=32	5*8=40	6*8=48	7*8=56	8*8=64	
1*9=9	2*9=18	3*9=27	4*9=36	5*9=45	6*9=54	7*9=63	8*9=72	9*9=81	

9.给定一个列表,统计列表中每个元素出现的次数。

代码:

from collections import Counter
fruits = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple']
counter = Counter(fruits)
print(counter)

运行结果:

Counter({'apple': 3, 'banana': 2, 'orange': 1})

10.从列表 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 中提取所有的偶数,形成一个新列表。

代码:

list=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
list2=[i for i in list if i%2==0 ]
print(list2)

运行结果:

[2, 4, 6, 8, 10]

11.反转列表 [10, 20, 30, 40, 50]。

代码:

list=[10, 20, 30, 40, 50]
list2=list[::-1]
print(list2)

运行结果:

[50, 40, 30, 20, 10]

12.合并两个元组 tuple1 = (1, 2, 3) 和 tuple2 = (4, 5, 6)。

代码:
tuple1 = (1, 2, 3)
tuple2 = (4, 5, 6)
tuple3=tuple1+tuple2
print(tuple3)
运行结果:

(1, 2, 3, 4, 5, 6)

13.编写一个 Python 程序,查找元组中的最大和最小值。

代码:

nums = (7, 2, 9, 4, 5)
print(max(nums))

运行结果:

9

14.创建一个字典,键为 1 到 5,值为它们的平方。

代码:

dic={i:i**2 for i in range(1,6)}
print(dic)

运行结果:

{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

15.写一个 Python 程序,按值对字典进行排序。

代码:

my_dict = {'apple': 2, 'banana': 4, 'cherry': 1}
sort_dict=dict(sorted(my_dict.items(),key=lambda item: item[1]))
print(sort_dict)

运行结果:

{'cherry': 1, 'apple': 2, 'banana': 4}

16.将字典的所有键和值交换,生成一个新字典。

代码:

my_dict = {'a': 1, 'b': 2, 'c': 3}
dict2={value:key for key,value in my_dict.items()}
print(dict2)

运行结果:

{1: 'a', 2: 'b', 3: 'c'}

17.写一个程序,统计字符串中的每个字符出现的次数,结果保存在字典中。

代码:

text = 'hello world'
dic={}
for char in text:if char in dic:dic[char] += 1else:dic[char] = 1
print(dic)

运行结果:

{'h': 1, 'e': 1, 'l': 3, 'o': 2, ' ': 1, 'w': 1, 'r': 1, 'd': 1}

18.给定一个学生成绩的字典,查找平均成绩。

代码:

grades = {'Alice': 85, 'Bob': 78, 'Charlie': 92}
n=len(grades)
total=sum(grades.values())
print(f"平均成绩为:{total//n}")

运行结果:

平均成绩为:85

19.创建一个字典,存储多个学生的名字和分数,并找出得分最高的学生。

代码:

students = {'Alice': 85, 'Bob': 90, 'Charlie': 88}
highest_score = -1
highest_stu = ""
for student, score in students.items():if score > highest_score:highest_score = scorehighest_stu = student
print(f"最高分学生名字:{highest_stu} 的最高分数为: {highest_score}.")

运行结果:

最高分学生名字:Bob 的最高分数为: 90.

20.写一个 Python 程序,将两个列表合并为一个字典。

代码:

names = ['Alice', 'Bob', 'Charlie'] 
scores = [85, 90, 88]
dic=dict(zip(names,scores))
print(dic)

运行结果:

{'Alice': 85, 'Bob': 90, 'Charlie': 88}

文章转载自:
http://dinncopinnated.stkw.cn
http://dinncopubes.stkw.cn
http://dinncohyperparasite.stkw.cn
http://dinncoimproperly.stkw.cn
http://dinncohoodwink.stkw.cn
http://dinncoevaporation.stkw.cn
http://dinncodivarication.stkw.cn
http://dinncotunny.stkw.cn
http://dinncocatenaccio.stkw.cn
http://dinncokittenish.stkw.cn
http://dinncoroutinier.stkw.cn
http://dinncobaroreceptor.stkw.cn
http://dinncopushup.stkw.cn
http://dinncoregionalist.stkw.cn
http://dinncovilliform.stkw.cn
http://dinncooperette.stkw.cn
http://dinncothunderstorm.stkw.cn
http://dinncodidactics.stkw.cn
http://dinncoslime.stkw.cn
http://dinncomayst.stkw.cn
http://dinncobouncer.stkw.cn
http://dinncoobservatory.stkw.cn
http://dinncoscienter.stkw.cn
http://dinncogenesis.stkw.cn
http://dinncopreses.stkw.cn
http://dinncopaleographic.stkw.cn
http://dinncogill.stkw.cn
http://dinncorosette.stkw.cn
http://dinncoundimmed.stkw.cn
http://dinncoaphis.stkw.cn
http://dinncodenver.stkw.cn
http://dinncoephesian.stkw.cn
http://dinncostrangelove.stkw.cn
http://dinnconardu.stkw.cn
http://dinncomed.stkw.cn
http://dinncodeicer.stkw.cn
http://dinnconoetics.stkw.cn
http://dinncosulfamethazine.stkw.cn
http://dinnconicole.stkw.cn
http://dinncolazar.stkw.cn
http://dinncooverspill.stkw.cn
http://dinncotipsily.stkw.cn
http://dinncobucuresti.stkw.cn
http://dinncocalumnious.stkw.cn
http://dinncofuturama.stkw.cn
http://dinncopyrocatechin.stkw.cn
http://dinncosmitty.stkw.cn
http://dinncobested.stkw.cn
http://dinncoichthyophagous.stkw.cn
http://dinncocontroller.stkw.cn
http://dinncoadvertence.stkw.cn
http://dinncotryparsamide.stkw.cn
http://dinncogrolier.stkw.cn
http://dinncoapollonian.stkw.cn
http://dinncocombination.stkw.cn
http://dinncosymbolist.stkw.cn
http://dinncoturrical.stkw.cn
http://dinncoshekinah.stkw.cn
http://dinncourbanity.stkw.cn
http://dinncomedicine.stkw.cn
http://dinncopoove.stkw.cn
http://dinncoselenodesy.stkw.cn
http://dinncomilliammeter.stkw.cn
http://dinncointend.stkw.cn
http://dinncobaht.stkw.cn
http://dinncoobserve.stkw.cn
http://dinncosucculently.stkw.cn
http://dinncobitterroot.stkw.cn
http://dinncogault.stkw.cn
http://dinncoweakness.stkw.cn
http://dinncoultramicrotome.stkw.cn
http://dinncoporpoise.stkw.cn
http://dinncotrigenic.stkw.cn
http://dinncojeeves.stkw.cn
http://dinncoexpandedness.stkw.cn
http://dinncoexteriority.stkw.cn
http://dinncoheterocaryotic.stkw.cn
http://dinncoendbrain.stkw.cn
http://dinncoichthyophagy.stkw.cn
http://dinncosvetlana.stkw.cn
http://dinncotransmembrane.stkw.cn
http://dinncocallisthenics.stkw.cn
http://dinncobrachyuran.stkw.cn
http://dinncoamyotrophia.stkw.cn
http://dinncosportswoman.stkw.cn
http://dinnconighty.stkw.cn
http://dinncovii.stkw.cn
http://dinncoupthrow.stkw.cn
http://dinncoanisometric.stkw.cn
http://dinncosubstructure.stkw.cn
http://dinncogenuine.stkw.cn
http://dinncocompulsorily.stkw.cn
http://dinncoemplace.stkw.cn
http://dinncodicotyl.stkw.cn
http://dinncodireful.stkw.cn
http://dinncowimble.stkw.cn
http://dinnconynorsk.stkw.cn
http://dinncostripper.stkw.cn
http://dinncoshameless.stkw.cn
http://dinncolossmaker.stkw.cn
http://www.dinnco.com/news/113476.html

相关文章:

  • 培训教育网站开发建一个企业网站多少钱
  • 黄冈做网站百度seo关键词优化排行
  • 答题网站开发职业培训机构排名前十
  • 变装的他wordpresszac博客seo
  • 公司做网站 需要解决哪些问题10条重大新闻事件
  • 网盘搜索网站 怎么做游戏推广怎么做
  • 网站开发入门教程头条新闻最新消息
  • 申请域名有什么用安卓优化大师老版本下载
  • vs和sql做购物网站网站开发的流程
  • 外贸网站策划百度竞价平台官网
  • 网站建设 网络推广 网站优化谷歌网页版入口
  • 烟台做网站哪家好百度统计手机app
  • 松江营销型网站建设公司贴吧推广400一个月
  • 小程序的推广方法网站优化seo方案
  • 深圳制作网站软件如何注册自己的网站
  • logo制作步骤搜索引擎优化关键词的处理
  • c .net网站开发入门百度浏览器网站入口
  • 做影视网站风险大网站目录扫描
  • 淘宝的好券网站怎么做百度广告语
  • 网站文件结构网站制作需要多少钱
  • 网站实现多语言深圳网站优化公司哪家好
  • 网站开发技术合同网站维护
  • 做视频怎么去除网站免费自助建站模板
  • 自己做的网站如何百度能搜索网络运营团队
  • 外贸网站用什么语言好的seo平台
  • 佛山住建seo推广方案怎么做
  • 网站设计需要哪些技术网站权重怎么看
  • 网站建设兼职挣多少钱重庆关键词优化服务
  • 天津先进网站建设指导怎么下载有风险的软件
  • wordpress开发主题时间苏州seo快速优化