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

建设通网站上线家乡网站建设策划书模板

建设通网站上线,家乡网站建设策划书模板,网站建设教程搭建汽岁湖南岚鸿专注,网站改版 报价大家好,小编来为大家解答以下问题,python代码大全和用法,python代码大全简单,现在让我们一起来看看吧! 火车头采集ai伪原创插件截图: 1、题目:列表转换为字典。 程序源代码: 1 #!/us…

大家好,小编来为大家解答以下问题,python代码大全和用法,python代码大全简单,现在让我们一起来看看吧!

 

火车头采集ai伪原创插件截图:

1、题目:列表转换为字典。

程序源代码:

1 #!/usr/bin/env python

2 #-*- coding: UTF-8 -*-

3

4 i = ['a', 'b']5 l = [1, 2]6 printdict([i, l])

以上实例输出结果为:

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

2、一个简单的while循环

1 #!/usr/bin/env python

2

3 count =04 while (count < 9):5 print 'The count is:', count6 count = count + 1

7

8 print "good bye"

以上实例输出的结果为:

The count is: 0

The countis: 1The countis: 2The countis: 3The countis: 4The countis: 5The countis: 6The countis: 7The countis: 8good bye

3、一个简单的循环continue

1 #!/usr/bin/env python

2 i = 1

3 while i < 10:4 i += 1

5 if i%2 >0:6 continue

7 print i

以上实例输出的结果为:

2

4

6

8

10

4、break的用法

1 #!/usr/bin/env python

2 i = 1

3 while 1:4 printi5 i += 1

6 if i > 10:7 break

以上实例的实验结果为:

1

2

3

4

5

6

7

8

9

10

5、 一个无限循环的小例子

1 #!/usr/bin/python

2 #-*- coding: UTF-8 -*-

3

4 var = 1

5 while var == 1: #该条件永远为true,循环将无限执行下去

6 num = raw_input("Enter a number:")7 print "You entered:", num8

9 print "Good bye!"

以上实例输出结果(使用ctrl + c 推出无限循环):

Enter a number:5You entered:5Enter a number:6You entered:6Enter a number:^CTraceback (most recent call last):

File"wuxian.py", line 6, in num= raw_input("Enter a number:")

KeyboardInterrupt

6、循环使用else?

1 #!/usr/bin/env python

2

3 count =04 while count < 5:5 print count, "is less than 5"

6 count = count + 1

7 else:8 print count, "is not less than 5"

以上实例结果

0 is less than 5

1 is less than 5

2 is less than 5

3 is less than 5

4 is less than 5

5 is not less than 5

7、题目:输入某年某月某日,判断这一天是这一年的第几天?

程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天:

程序源代码:

1 #!/usr/bin/python

2 #-*- coding: UTF-8 -*-

3

4 year = int(raw_input('year:'))5 month = int(raw_input('month:'))6 day = int(raw_input('day:'))7

8 months = (0,31,59,90,120,151,181,212,243,273,304,334)9 if 0 < month <= 12:10 sum = months[month - 1]11 else:12 print 'data error'

13 sum +=day14 leap =015 if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)): #能被400或者4整除,但不能被100整除是闰年

16 leap = 1

17 if (leap == 1) and (month > 2):18 sum += 1

19 print 'it is the %dth day of this year.' %sum

以上实例的输出结果:

year: 2016month:11day:2itis the 307th day of this year.

8、题目:输入三个整数x,y,z,请把这三个数由小到大输出火车头标题伪原创。

程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,然后再用x与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小。

程序源代码:

1 #!/usr/bin/python

2 #-*- coding: UTF-8 -*-

3

4 l =[]5 for i in range(3):6 x = int(raw_input('integer:'))7l.append(x)8l.sort()9 print l

以上实例的输出结果:

integer: 4integer:7integer:1[1, 4, 7]

9、题目:将一个列表的数据复制到另一个列表中。?

程序分析:使用列表[:]。

程序源代码:

1 #!/usr/bin/python

2 #-*- coding: UTF-8 -*-

3

4 a = [1, 2, 3]5 b =a[:]6 print b

以上实例输出结果为:

[1, 2, 3]

10、题目:输出9*9乘法口诀表。

程序分析:分行与列考虑,共9行9列,i控制行,j控制列。

程序源代码:

1 #!/usr/bin/python

2 #-*- coding: UTF-8 -*-

3

4 for i in range(1,2):5 for j in range(1,10):6 result = i *j7 print '%d * %d = % -3d' %(i,j,result)8 print ''

以上实例的结果:?

1 * 1 = 1

1 * 2 = 2

1 * 3 = 3

1 * 4 = 4

1 * 5 = 5

1 * 6 = 6

1 * 7 = 7

1 * 8 = 8

1 * 9 = 9

11、python的标准输出

1 #!/usr/bin/env python

2 #_*_ coding:utf-8 _*_

3 name=input("name:")4 age=int(input("age:"))5 job=input("job:")6 salary=float(input("salary:"))7 info2='''8 ==================info of {_name}=================

9 name:{_name}

10 age:{_age}

11 job:{_job}

12 salary:{_salary}

13 ==================================================

14'''.format(_name=name,15 _age=age,16 _job=job,17 _salary=salary)18 print(info2)

12、一个python输入密码的小程序,在输入密码时,为了使密码不可见,可以条用getpass模块的getpass()方法。

1 #!/usr/bin/env python

2 #_*_ coding:utf-8 _*_

3 importgetpass4 user =raw_input("请输入用户名:")5 pwd=getpass.getpass("请输入密码:")6 print(user, pwd)

以上实例的输出结果:

#python passwd.py

请输入用户名:wangtao

请输入密码:

('wangtao', '123456')

13、使用sys模块的小例子

1 #!/usr/bin/env python

2 from sys importargv3 printargv

以上实例的输出结果:

#python argvtest.py 1 2 3 4 5

['argvtest.py', '1', '2', '3', '4', '5']

14、猜数字的小游戏

1 #!/usr/bin/env python

2 #_*_ coding:utf-8 _*_

3

4 time=05 real_age=23

6 while time<3:7 guess_age=int(raw_input("请猜猜我的真实年龄,请输入猜测的年龄:"))8 if guess_age==real_age:9 print("哈哈,你真聪明猜对了!")10 break

11 elif guess_age>real_age:12 print("数字太大了,请猜小一点!")13 else:14 print("数字有些小,请猜大一点!")15 time += 1

16 if time==3:17 continue_flag = raw_input("还要继续往下猜吗?(yes or no)")18 if continue_flag == "y":19 time=020 else:21 print("退出系统! ")22 break

以上实例的输出结果:

#python guess_agetest.py

请猜猜我的真实年龄,请输入猜测的年龄:35数字太大了,请猜小一点!

请猜猜我的真实年龄,请输入猜测的年龄:232数字太大了,请猜小一点!

请猜猜我的真实年龄,请输入猜测的年龄:34数字太大了,请猜小一点!

还要继续往下猜吗?(yesorno)y

请猜猜我的真实年龄,请输入猜测的年龄:12数字有些小,请猜大一点!

请猜猜我的真实年龄,请输入猜测的年龄:23哈哈,你真聪明猜对了!

15、for循环的小例子

#!/usr/bin/env python#_*_ coding:utf8 _*_#author:snate

for i in range(0,10,3):print("loop",i)if i>=6:break

以上实例的输出结果为:

#python for.py

('loop', 0)

('loop', 3)

('loop', 6)

16、显示目录文件

>>> importsubprocess>>> subprocess.call(["ls","-l","/tmp/"])

total84

-rw-r--r-- 1 root root 1702 Feb 24 10:44 6379.conf-r--r--r-- 1 root root 74812 Oct 25 10:53 cronie-1.4.4-12.el6.x86_64.rpm

drwxr-xr-x 2 root root 4096 Feb 24 16:46 hsperfdata_root

17. python包装ls命令

#!/usr/bin/env python#python wrapper for the ls command

importsubprocess

subprocess.call(["ls","-l","/tmp"])

18. 显示系统信息脚本

#!/usr/bin/env python#A system information gathering

importsubprocess#command 1

uname = "uname"uname_arg= "-a"

print "Gathering system information with %s command: " %uname

subprocess.call([uname, uname_arg])#command 2

diskspace = "df"diskspace_arg= "-h"

print "Gathing diskspace information %s command: " %diskspace

subprocess.call([diskspace,diskspace_arg])

http://www.yayakq.cn/news/282096/

相关文章:

  • 购物网站的设计与实现如何在百度中搜索到网站
  • 网站总类微信公众平台内做网站
  • 平台网站开发的税率阿里与电信签订合作协议
  • 网站建设与管理实训心得体会如何提高网站安全性
  • 大网站整站备份广州公司营销型网站建设
  • 开发app需要公司吗网站优化定做
  • 一般网站建设收费几年合同网络公司排名最新排名
  • 商城网站模板htmlwordpress付费阅读主题
  • 西安网站建设定制江门建站网站模板
  • 公司建站方案百度seo排名查询
  • 网站弹出窗口js网络销售平台怎么做
  • 网站怎么申请域名网站策划方案案例
  • 南阳网站建设费用外贸网站建设解决方案
  • 天津建设与管理局网站沈阳建设工程信息网官方网站
  • 漯河优惠网站建设价格阳江网梁国燊事件
  • 怎么开彩票网站做站长中国北京出啥大事了
  • 一个网站seo做哪些工作小程序商城图片素材
  • 公司网站开发后台代码wordpress wampsever
  • 哪里有零基础网站建设教学公司WordPress自助提交友情链接
  • 快递公司网站源码怎么用qq邮箱做网站
  • 网站建设营销怎么做网站做数据分析
  • 石家庄企业做网站创业过程中网站建设
  • 单位网站建设情况说明书有哪些做的好的营销型网站
  • 徐州集团网站建设报价开封市住房和城乡建设 网站
  • 网站开发年终总结外贸网站推广计划
  • 网站综合建设笔记哪里有网站建设培训班
  • 网站托管怎做花都区水务建设管理中心官方网站
  • 医院网站优化方案江门推广平台排行榜
  • 一个网站如何工作流程网站建设客户人群
  • p2p理财网站开发流程图cn域名有名的网站