#10-1
with open(r'learning_python.txt') as file_object:
#line
for line in file_object:
print(line.rstrip())
with open(r'learning_python.txt') as file_object:
#file
contents = file_object.read()
print(contents)
with open(r'learning_python.txt') as file_object:
#list
lines = file_object.readlines()
for line in lines:
print(line.rstrip())
#10-3
name = input("What's your name: ")
with open("name.txt", 'w') as file_object:
file_object.write("name")
#10-6
try:
first_num = input("please input the first numble:")
first_num = int(first_num)
second_num = input("please input the second numble:")
second_num = int(second_num)
except(ValueError):
print("please make sure to input a numble!")
else :
print(first_num + second_num)
#10-11
import json
fnum = input("please input your favourite numble: ")
with open("favourite_num.json", 'w') as file_object:
json.dump(fnum,file_object)
with open("favourite_num.json") as file_object:
num = json.load(file_object)
print("I know your favourite number! It's " + str(num))
python学习第5周(2)
最新推荐文章于 2023-03-21 21:44:41 发布