python3 生成随机数

#!/usr/bin/env python
# encoding: utf-8
# @Time    : 2019/5/21 22:13
# @Author  : ZengChenyu
# @Site    : 
# @File    : test.py
# @Software: PyCharm
from random import randint

f = open("data.txt", 'w')	#输出到文件
#for i in range(0, 10):
i = 0
while i < 10:
    i += 1
    ch = chr(randint(0, 25) + 65)	#randint生成闭区间整形随机数  chr生成的随机数转ASCII字符
    print(ch, end="", file=f)	#end输出的结尾不空格或者是换行
f.close()

发布了30 篇原创文章 · 获赞 43 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/qq_43041976/article/details/90440163