10-3 访客
filename="program.txt" with open(filename,'w') as file_object: name=input("Please input your name") file_object.write(name)
10-5 关于编程的调查
filename="why.txt" with open(filename,'r+') as file_object: while(True): reason=input("Why do you like programming? ") if(reason): file_object.write(reason) else: break
10-6 加法运算
print("Give e two numbers,and I will add them") while(True): first=input("First number: ") second=input("Second number: ") try: answer=int(first)+int(second) except ValueError: print("You can only print numbers!") else: print(answer)