python训练过程是什么_【Python-基础训练】

1.简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型。

答:

编译型语言:

使用专门的编译器,针对特定的平台,将高级语言源代码一次性的编译成可被该平台硬件执行的机器码,并包装成该平台所能识别的可执行性程序的格式。

特点:

在编译型语言写的程序执行之前,需要一个专门的编译过程,把源代码编译成机器语言的文件.

执行方式:

源代码 ———> 编译(一次编译) ———>目标代码———>执行(多次执行)———>输出

解释型语言:

使用专门的解释器对源程序逐行解释成特定平台的机器码并立即执行。

特点:

解释型语言不需要事先编译,其直接将源代码解释成机器码并立即执行,所以只要某一平台提供了相应的解释器即可运行该程序。

执行方式:

源代码 ———> 解释器(每次执行都需要解释)———>输出

编译型: C、C++

解释型:Python、PHP、Ruby、Java

2.执行 Python 脚本的两种方式是什么?

1、./run.py.shell直接调用python脚本

2、python run.py 调用python 解释器来调用python脚本

3.Pyhton 单行注释和多行注释分别用什么?

1. 单行注释使用 # 号

2. 多行注释使用 """ ......""", '''...........'''

4.布尔值分别有什么?

布尔值分别有:True 和False, 布尔值为False的有:[] () {} 0 False "" 等

1 #-*- coding: utf-8 -*-

2 a =()3 b =[]4 c ={}5 d = ""

6 e =07

8 ifa :9 print(a)10 ifb :11 print(b)12 ifc :13 print(c)14 ifd :15 print(d)16 ife :17 print(e)18 print("---end---")

5.声明变量注意事项有那些?

模块名\包名 :小写字母, 单词之间用_分割

类名:首字母大写

全局变量: 大写字母, 单词之间用_分割

普通变量: 小写字母, 单词之间用_分割

函数: 小写字母, 单词之间用_分割

实例变量: 以_开头,其他和普通变量一样

私有实例变量(外部访问会报错): 以__开头(2个下划线),其他和普通变量一样

专有变量: __开头,__结尾,一般为python的自有变量(不要以这种变量命名)

6.如何查看变量在内存中的地址?

#-*- coding: utf-8 -*-

a = 1b= 1c= 2d= 2

print(id(a))print(id(b))print(id(c))print(id(d))

执行结果:140732753687376

140732753687376

140732753687408

140732753687408

7.编程

1 #-*- coding: utf-8 -*-

2 '''

3 编码:实现“用户输入用户名和密码,4 当用户名为 seven 或 alex 且 密码为 123 时,5 显示登陆成功,否则登陆失败。6 失败时允许重复输入三次。”7 '''

8

9 userlist = ['seven' , 'alex']10 passwd = '123'

11 count = 1

12

13 while count <= 4:14 name = input("Name:")15 pwd = input("Password:")16 if name in userlist and pwd ==passwd:17 print("登陆成功")18 break

19 else:20 print("第%d次登陆失败"%count)21 count+=1

22 print("------------")

1 #-*- coding: utf-8 -*-

2

3 #(1)使用while循环实现输出2-3+4-5+6...+100 的和4 sum = 05 i = 26 while i <= 100:7 if i%2 != 0:8 sum = sum -i9 else:10 sum = sum + i11 i = i + 112 print("2-3+4-5+6...+100=%d"%sum)13 #(2)使用 while 循环实现输出 1,2,3,4,5,7,8,9,11,1214 sum = 015 i = 016 while i <= 11:17 i = i + 118 if i == 6 or i==10:19 continue20 else:21 print(i, end=' ')22

23 print("\n-----------")24 #(3)使用while 循环输出100-50,从大到小,如100,99,98...,到50时再从0循环输出到50,然后结束25 i = 10026 while i >= 0 :27 if i > 50:28 print(i, end=' ')29 else:30 print(50-i, end=' ')31 i = i - 132 #(4)使用 while 循环实现输出 1-100 内的所有奇数33 i = 134 while i <= 100:35 if i%2 ==0:36 print(i, end=' ')37 i = i + 138 #(5)使用 while 循环实现输出 1-100 内的所有偶数39 i = 140 while i <= 100:41 if i%2 !=0:42 print(i, end=' ')43 i = i + 1

#输入一年份,判断该年份是否是闰年并输出结果。

1 defget_year(year):2 if year%4 ==0 and year%100 !=0 or year%400 ==0:3 print("闰年")4 else:5 print("不是闰年")6

7 if __name__ == "__main__":8 get_year(1900)

#假设一年期定期利率为3.25%,计算一下需要过多少年,一万元的一年定期存款连本带息能翻

1 money = 100000

2 rate = 0.0325

3 year =04

5 while money <=200000:6 money = money + money*rate7 year = year + 1

8

9 print(year)

#球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?

1 count = 1

2 height = 100.0

3 meter = 0.0

4

5 while count <= 10:6 meter = meter +height7 print("第%s次落地的下落高度:%s"%(str(count),str(meter)))8 height = height / 2

9 print("第%s次落地的反弹高度:%s" %(str(count), str(height)))10 meter= meter +height11 print("第%s次的经过:%s" %(str(count), str(meter)))12 count = count + 1

13

14 '''

15 150.0 50.016 225.0 25.017 262.5 12.518 281.25 6.2519 290.625 3.12520 295.3125 1.562521 297.65625 0.7812522 298.828125 0.39062523 299.4140625 0.195312524 299.70703125 0.0976562525 '''

1 #-*- coding:utf-8 -*-

2 '''

3 *4 * *5 * * *6 * * * *7 * * * * *8 * * * *9 * * *10 * *11 *12 '''

13 line = 1

14 while line < 10:15 if line >= 6:16 print("*"*(10-line))17 else:18 print("*"*line)19 line = line + 1

1 #-*- coding:utf-8 -*-

2 '''

3 编写登陆接口+4 基础需求:5 1.让用户输入用户名,密码6 2.认证成功后显示欢迎信息7 3.输错三次后退出程序8 4.可以支持多个用户登录 (提示,通过列表存多个账户信息)9 5.用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里)10 '''

11

12 #1.定义用户列表,用于缓存

13 user_status ={}14

15 #2.从文件中读取用户状态

16 fp = open('userList.txt', 'r+')17 for user infp.readlines():18 templist = user.strip().split(":")19 if templist[0] inuser_status:20 if user_status[templist[0]] != '3':21 user_status[templist[0]] =022 else:23 user_status[templist[0]] = templist[1]24 else:25 user_status[templist[0]] = templist[1]26 fp.close()27

28 #3.登陆

29 passwd = '123'#密码

30 count = 1#计数器

31 flag = True#控制器

32 whileflag:33 name = input("Name:")34 pwd = input("Password:")35 if name inuser_status:36 if user_status[name] == '3':37 print("》》》用户账号已锁定,请联系管理员")38 else:39 if passwd ==pwd:40 print("》》》登陆成功")41 break

42 else:43 if count == 3 and user_status[name] == '2':44 print("》》》登陆失败,用户将锁定")45 user_status[name] = '3'

46 break

47 else:48 print("》》》密码输入错误")49 user_status[name] =str(count)50 count = count + 1

51 else:52 print("》》》用户名不存在")53 dec = input("Continue or not(Y/N):")54 if dec.lower() == 'n':55 flag =False56 print("系统退出")57 elif dec.lower() == 'y':58 flag =True59 else:60 print("输入异常,退出")61 flag =False62

63 #4.将结果写入文件

64 fp = open('userList.txt', 'r+')65 for user inuser_status:66 fp.write(user+":"+user_status[user]+"\n")67 fp.close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值