当前位置:网站首页>Prompt the user to enter his name, and the user will write his name to the file guest Txt program determines that when it is not equal to N, it executes to create the file data Txt, a total of 100000
Prompt the user to enter his name, and the user will write his name to the file guest Txt program determines that when it is not equal to N, it executes to create the file data Txt, a total of 100000
2022-04-22 07:18:00 【Gratifying clover (●  ̄ (エ)  ̄ ●)】
1. visitor : Write a program , Prompt the user to enter his name ; After the user responds , Write its name Import to file guest.txt in . Program judgment should not be equal to n When , Is executed .
name = input(' Please enter a user name :')
def PanDuan():
if name != 'n':
with open('guest.txt', 'w') as f:
f.write(name)
with open('guest.txt', 'r') as f:
print(' The contents of the written file are :', end=' ')
print(f.read())
if __name__ == '__main__':
PanDuan()

2. create a file data.txt, Documents in total 100000 That's ok , One for each line 1~100 A random integer between
import random
def Get_Number():
for i in range(1, 100001):
number = random.randint(1, 100)
jieguo = ' The first {} That's ok :{}'.format(i, number) + '\n'
with open('data.txt', 'a') as f:
f.write(jieguo)
Get_Content()
def Get_Content():
with open('data.txt', 'r') as f:
print(' The content of the document is :')
print(f.read())
if __name__ == '__main__':
Get_Number()

版权声明
本文为[Gratifying clover (●  ̄ (エ)  ̄ ●)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220609573348.html
边栏推荐
- Mongodb install self start service
- . net learning notes (I) -- introduction, advantages, design ideas, principles and applications of generics
- Robomaster大疆飞手考核
- Wechat browser cannot save cookies for a long time
- macOS安装redis并设置服务自启动
- 定义一个学生Student类1 获取学生的姓名:get_name() 返回类型:str 2 获取学生的年龄:get_age() 返回类型:int 3 返回3门科目中最高的分数。get_course()
- Introduction to IC Analog Layout - learning notes on layout Basics (4)
- 1、编写学生信息管理系统以下三个模块:并检测执行。 1、添加学生信息 4、查询学生信息 5、查询全部学生信息
- ASP. Net daily development notes ----- IIS server supports downloading APK
- 假设成年人的体重和身高存在此种关系: 身高(厘米)-100=标准体重(千克) 如果一个人的体重与其标准体重的差值在正负5%之间,显示“体重正常”,其他则显示“体重超标”。编写程序,能处理用户输入的
猜你喜欢

JS实现点击头像上传图片修改

C daily development notes -- solve the problem that one set references another set, resulting in changes together

左移与右移

定义一个抽象的Role类有姓名年龄性别爱好等成员变量要求尽可能隐藏所有变量(能够私有就私有)再通过Get()和Set()方法对各变量进行读写,其中龄必须在0到150岁性别必须是男或者女姓名必须是2个字

Shift left and right

New year's greetings & wishes to all programmers
![ERROR: [Hsi 55-1545] ,无法正常生成fsbl,Unable to read in MSS file,Failed to closesw system.mss](/img/4e/34e2820ff8579007b20b33b27d8f1d.png)
ERROR: [Hsi 55-1545] ,无法正常生成fsbl,Unable to read in MSS file,Failed to closesw system.mss

Introduction to IC Analog Layout - learning notes on layout Basics (I)

Format control of format() method

C语言 | 快速排序
随机推荐
Notes on C # daily development ----- obtain all files in the zip in Huawei cloud bucket (including system. Notsupportedexception: "this stream does not support search operation" solution)
Goodbye, postman. One thing to say: apifox is yyds
MacOS installs redis and sets the service self start
. net learning notes (I) -- introduction, advantages, design ideas, principles and applications of generics
Preparation before analog circuit board commissioning_ Analog circuit board
Comparison and improvement of Nacos service registration center
Noi / 1.5.25: finding special natural numbers
提示用户输入其名字 用户作出响应后 将其名字写 入到文件guest.txt 中 程序判断当不等于n的时候,就执行 创建文件data.txt,文件共10万行,每行存放一个1~100之间的随机一个整数
Parseexception unparseable date time conversion exception
日常开发随手记------VS上一些好用的设置
【Bug小记】antd表格高度自适应窗口高度
C#日常开发随手记------获取华为云桶中ZIP内的所有文件(包含System.NotSupportedException:“此流不支持查找操作“解决方法)
ASP.NET日常开发随手记------webService服务端开发
C#日常开发随手记----解决一个集合引用另一个集合导致一起改变
Format control of format() method
【SVN】Subversion安装使用笔记
Pixhawk4+Up Board / NUC Implement VIO By Deploying T265
MongoDB安装自启动服务
写一个方法sanjiao(a, b, c),判断三个参数是否能构成一个三角形,如果不能则抛出异常IllegalArgumentException,显示异常信息a,b,c”不能构成三角形”,如果可以
Difference between analog IC design and digital IC design, including salary table