下面是最近写的一些python3版本的一些练习题:

1、4+44+444+4444+.....+=?

root@wadeson:~/study_for_python/homework# cat aa.py
#!/usr/bin/python3 n = int(input("please input a number: "))
init_num = int(input("pleasr input a init number: "))
total = 0
num1 = 0 for i in range(n):
num1 = num1 + (10**i)*init_num
total = total + num1 print(total)

运行结果:

root@wadeson:~/study_for_python/homework# python3 aa.py
please input a number: 3
pleasr input a init number: 4
492

2、九九乘法表:

root@wadeson:~/study_for_python/circle# cat while_about_nine2.py
#!/usr/bin/python3 num1 = 1
while num1 <= 9:
num2 = 1
while num2 <= 10 - num1: # num2从9开始依次减小
print("%d * %d = %d" % (num2,num1,num1*num2), end=" ") # num2总是从1开始循环,并且循环到num1的值,end=" "表示不换行,空格间隔
num2 = num2 + 1
print() # 作用是换行
num1 = num1 + 1

运行如下:

root@wadeson:~/study_for_python/circle# python3 while_about_nine2.py
1 * 1 = 1 2 * 1 = 2 3 * 1 = 3 4 * 1 = 4 5 * 1 = 5 6 * 1 = 6 7 * 1 = 7 8 * 1 = 8 9 * 1 = 9
1 * 2 = 2 2 * 2 = 4 3 * 2 = 6 4 * 2 = 8 5 * 2 = 10 6 * 2 = 12 7 * 2 = 14 8 * 2 = 16
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9 4 * 3 = 12 5 * 3 = 15 6 * 3 = 18 7 * 3 = 21
1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16 5 * 4 = 20 6 * 4 = 24
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
1 * 7 = 7 2 * 7 = 14 3 * 7 = 21
1 * 8 = 8 2 * 8 = 16
1 * 9 = 9

或者如下:

root@wadeson:~/study_for_python/circle# cat while_about_nine.py
#!/usr/bin/python3 num1 = 1
while num1<=9:
num2 = 1
while num2 <= num1: # num2依次从1开始增大到9
print("%d * %d = %d" % (num2,num1,num1*num2), end=" ")
num2 = num2 + 1
print()
num1 = num1 + 1
root@wadeson:~/study_for_python/circle# python3 while_about_nine.py
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

3、打印*符号:

root@wadeson:~/study_for_python/circle# cat while_2.py
#!/usr/bin/python3 line = 4
num = line
while line > 0:
num1 = 0
while num1 <= num - line:
print("*", end="")
num1 = num1 + 1 print("")
line = line - 1

运行结果如下:

root@wadeson:~/study_for_python/circle# python3 while_2.py
*
**
***
****
root@wadeson:~/study_for_python/circle# cat while_1.py
#!/usr/bin/python3 num = 1
line = 4 while num <= line:
num1 = 0
while num1 <= line - num:
print("*", end="")
num1 = num1 + 1 print("")
num = num + 1
root@wadeson:~/study_for_python/circle# python3 while_1.py
****
***
**
*

4、验证账户信息,如果是锁住的账户,则直接登录失败;如果没有注册的账户,请先进行注册;如果输入账号密码错误三次则锁住该账户;如果登录成功,则打印成功信息

root@wadeson:~/study_for_python/homework# cat authenticate_user_land.py
#!/usr/bin/python3
import getpass user_list = {}
lock_user = [] # 读取文件中的的账号和密码保存在用户字典中
with open("user_list.txt","r") as f1:
for i in f1.readlines():
(user,passwd) = i.strip().split()
user_list[user] = passwd # 读取锁用户文件中的user保存在列表中
with open("lock_user.txt","r") as f2:
for i in f2.readlines():
user = i.strip()
lock_user.append(user) user_get=input("please input user:")
passwd_get=getpass.getpass("please input password:")
T = 0 while T < 2:
# 当输入的名字存在于锁用户中时,直接退出
if user_get in lock_user:
print("your user %s has been locked,please contact administrator" % user_get)
break
# 当输入的用户不存在锁用户中:1,账号密码进行判断三次 2,账号不存在
else:
if user_get not in user_list.keys():
print("user %s is not exist,please register!" % user_get)
break
else:
if passwd_get == user_list[user_get]:
print("welcome to %s" % user_get)
break
else:
print("your password is wrong,please try again")
T = T + 1
user_get=input("please input user:")
passwd_get=getpass.getpass("please input password:") else:
print("your user %s has been locked!" % user_get)
lock_user.append(user_get)
with open("lock_user.txt","w") as f_lock:
for i in lock_user:
f_lock.write("%s\n" % i)
root@wadeson:~/study_for_python/homework# cat lock_user.txt
user1
wadeson
root@wadeson:~/study_for_python/homework# cat user_list.txt
wadeson redhat
jsonhc redhat
root@wadeson:~/study_for_python/homework# python3 authenticate_user_land.py
please input user:wadeson
please input password:
your user wadeson has been locked,please contact administrator
L1 = [1, 2, 3, 4, 5]
L2 = ["a", "b", "c", "d", "e"]
L = ['1a', '2b', '3c', '4d', '5e']
L1 = [1, 2, 3, 4, 5]
L2 = ["a", "b", "c", "d", "e"]
L = []
i = 0
j = 0
while i < len(L1):
while j < len(L2):
t = "%s%s" % (L1[i], L2[j])
L.append(t)
j = j + 1
i = i + 1
print(L)

持续更新中

python3的一些练习题的更多相关文章

  1. python3的基础练习题

    1. 执行 Python 脚本的两种方式 1)/usr/bin/python3 xx.py 2)python3 xx.py #注xx.py需要在内容里面调用由什么解释器执行 2. 简述位.字节的关系 ...

  2. python3 class类 练习题

    """一.定义一个学生Student类.有下面的类属性:1 姓名 name2 年龄 age3 成绩 score(语文,数学,英语) [每课成绩的类型为整数] 类方法:1 ...

  3. Python3.x 基础练习题100例(51-60)

    练习51: 题目: 学习使用 按位与(&) . 分析: 0&0=0; 0&1=0; 1&0=0; 1&1=1. 程序: if __name__ == '__ma ...

  4. Python3.x 基础练习题100例(41-50)

    练习41: 题目: 模仿静态变量的用法. 程序: def varfunc(): var = 0 print('var = %d' % var) var += 1 if __name__ == '__m ...

  5. Python3.x 基础练习题100例(31-40)

    练习31: 题目: 请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母. 分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语句判断第二个字母. 程序 ...

  6. Python3.x 基础练习题100例(21-30)

    练习21: 题目: 猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个第二天早上又将剩下的桃子吃掉一半,又多吃了一个.以后每天早上都吃了前 一天剩下的一半零一个.到第10天早上 ...

  7. Python3.x 基础练习题100例(11-20)

    练习11: 题目: 古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 分析: 兔子的规律为数列1,1,2, ...

  8. Python3.x 基础练习题100例(01-10)

    练习01: 题目: 有四个数字:1.2.3.4,能组成多少个互不相同且无重复数字的三位数?各是多少? 分析: 可填在百位.十位.个位的数字都是1.2.3.4.组成所有的排列后再去 掉不满足条件的排列. ...

  9. Python3.x 基础练习题100例(61-70)

    练习61: 题目: 打印出杨辉三角形. 程序: if __name__ == '__main__': a = [] for i in range(10): a.append([]) for j in ...

随机推荐

  1. c++11——lambda表达式

    lambda表达式 函数式编程的一个语法,有如下优点: (1)声明式编程风格:就地匿名定义目标函数或函数对象,不需要额外写一个命名函数或者函数对象.以更直接的方式写程序,好的可读性和可维护性. (2) ...

  2. font-size对展示的影响

    实例: <head>        <style type="text/css">            span{display: inline-bloc ...

  3. vue报错一

    8080端口被占用 解决方案: 打开cmd输入:netstat -ano查看所有端口信息,如图,找到端口 8080,以及对应的 PID: 输入:tskill PID 即可杀死进程,ex:: tskil ...

  4. Egret置于后台时,暂停游戏逻辑 (Egret 5 )

    官网教程-生命周期:http://developer.egret.com/cn/2d/lifecycle 主要是在游戏置于后台时,关闭游戏逻辑.渲染逻辑和背景音乐,保证更好的用户体验. 一 Egret ...

  5. javaWeb项目springMVC框架下利用ITextpdf 工具打印PDF文件的方法(打印表单、插入图片)

    方法一:打印PDF表单以及在PDF中加入图片 需要的资料: jar包:iTextAsian.jar ,itext-2.1.7.jar: 源码: public static void main(Stri ...

  6. Animate CC 2017

    一.Animate CC 2017 下载及安装 http://www.ddooo.com/softdown/86853.htm

  7. postgresql----Gist索引

    GiST的意思是通用的搜索树(Generalized Search Tree). 它是一种平衡树结构的访问方法,在系统中作为一个基本模版,可以使用它实现任意索引模式.B-trees, R-trees和 ...

  8. OA之框架的搭建

    1.使用框架可以有效的解决耦合性过高的问题,减少代码修改的程度,同时方便添加新的功能.首先创建出基本的几个类库.这个框架就是使用基本的逻辑分层三层架构,然后进一步再使用接口对每个逻辑中的类库调用进行解 ...

  9. 使用 Sonar 进行代码质量管理

    参考资料: 使用 Sonar 进行代码质量管理 SonarQube的安装.配置与使用 SonarLint(Sonar) 代码质量管理

  10. Linux的操作系统I2C驱动架构解说

    Linux的操作系统I2C驱动架构解说 发布时间:2006.10.16 04:52 来源:赛迪网技术社区 作者:LoneStar 最近因为工作需要涉及到了I2C总线.虽然我过去用过I2c,但看了 Li ...