您的位置:首页 > 编程语言 > Python开发

python第一天练习题

2017-12-28 01:09 218 查看

练习题:

1、答:

编译型开发效率低,因为编译型是每次写完一次代码后打一次,那么就是代码里面有问题的时候,我们需要重新编写代码并且打包。例如:c、c++等

解释型的开发效率高,当我们代码有问题的时候,我们可以边改边执行代码。例如:python等
2、答:
执行python脚本的两种方式分别是:python xx.py 和直接回车。
3、答:
单行注释表示描述
多行注释表示展示
4、答:
布尔值分别有True和False。
5、答:
声明变量注意首字母是英文,不能过长
6、答:
id
id(x)得到x变量的内存地址(10进制)
第7题第一小问
name = "seven"
password = "123"

u_name = input("your name:")
u_password = input("your password:")
if u_name == name and u_password == password :
print("登录成功")
else:
print("登录失败")

#第7题第二小问

name = "seven"
password = "123"
count = 0

while count < 3:
u_name = input("your name:")
u_password = input("your password:")
if u_name == name and u_password == password :
print("登录成功")
else:
print("登录失败")
count += 1

第7题第三小问
count = 0
while count < 3:
u_name = input("your name:")
u_password = input("your password:")
if u_name == "seven" and u_password == "123" :
print("登录成功")
break
elif u_name == "alex" and u_password == "123" :
print("登录成功")
break
else:
print("登录失败")
count += 1

第8题a
count = 2
num = 0
while count <=100 :
if count % 2 == 0:
num += count
elif count % 2 != 0:
num -= count
count += 1
print(num)

第8题b
count = 1
while count < 13:
if count != 6:
print("count", count)
count += 1

第8题d
count = 0
while count <= 100:
if count % 2 != 0:
print("count",count)
count += 1

第8题e
count = 1
while count <= 100:
if count % 2 == 0:
print("count",count)
count += 1

第9题
n1和n2是变量。
第一句话:n1 = 123456 //赋予了变量n1的值123456
第二句话:n2 = n1 //n2的值指向n1的值,所以n2的值也是123456

作业---编写登录接口
name = "nie"
password = "123"
count = 0
while count < 3:
u_name = input("name:")
u_password = input("password:")
if u_name == name and u_password == password:
print("welcome !!!")
break
else:
print("once agine!!!")
count += 1

升级优化
div={
'list1':{'password':'123456'},
'list2':{'password':'123456'},
'list3':{'password':'123456'},
}
f = open("black_user.txt",'r')
lock_file = f.readlines()
f.close()
count=0
count1=0
while True:
name_input=input("please input name:")
if count == 3:
print("用户名输入次数到达限制")
break
if  not name_input in div:
print("用户名错误")
count +=1
if  name_input in lock_file:
print("户名已锁定,暂停使用!")
exit()

if name_input in div:
count -=2
password_input=str(input("please input password:"))
if password_input == div[name_input]['password']:
print ("密码成功")
break
else:
print("密码错误")
count1 +=1
if count1 == 2:
print("您输入的密码错误次数已达3次,将锁定您的账户!")
f = open('black_user', 'w')
f.write('%s'%name_input)
f.close()
break
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  初学 python