#
Import math
Print (dir(math))
Open (“[Link]”,`w’,encoding =’utf -8) as f:
[Link](“my first file \n”)
[Link](“this file\n”)
[Link](“contains three lines \n”)
F=open(“[Link]”,’r’,encoding = ‘utf-8’)
Print([Link]())
F=open(“[Link]”,’r’,encoding =’utf-8’)
[Link]()
print([Link](4))
[Link](0)
print([Link](4))
F=open(“[Link]”,’r’,encoding =’utf-8’)
For line in f:
Print(line)
F=open(“[Link]”,’r’,encoding =’utf-8’)
For line in f :
Print(line,end=”)
F=open(“[Link]”,’r’,encoding =’utf-8’)
Print([Link])
Print([Link])
#
Import os
Current –directory = [Link] cwd()
Print(current – directory)
Import os
Folder-path= ‘c:\users\\ausus\\dekstop\\test-directory
Result = [Link](folder_path)
Print(result)
Import os
[Link](‘test’)
Import os
[Link] (‘test’,’new-test)
Import os
[Link](‘test’,’c:/users/asus/desktop/test’)
Import os
[Link]() (“new-one”,’[Link]’)
[Link](‘[Link]’)
[Link]()(‘new-one’)
[Link]()[‘new-one’]
[Link](‘new-one)
[Link]()
[]
Import shutil
[Link](‘test’)
#
Traceback (most recent call list):
File “..\[Link]”,line 1,in <module>
Print(1/0)
Def find reciprocal (value):
Try:
Print(“value:”,value)
R=1/value
Print(“the reciprocal of”,value, “is”,r,”\n”)
Except:
Print(“you cannot find reciprocal of”,value,”\n”)
Find reciprocal (“hello”) find reciprocal(2)
Def find reciprocal (value):
Try:
Print(“value:”,value)
r=1/value
Print(“reciprocal of”,value,”is”,r)
Except value error:
Print(“you got value error”)
Except zero division error:
Print(“handling all other errors”)
Find reciprocal (0)
A=int(input(“enter a positive integer:”)
Try: if a<=0:
Raise value error (“not a positive number)
Print(“you entered “,a)
Except value error as ve:
Print(ve)
Try: F=open(“[Link]”,’r’,encoding =’utf-8’)
Finally:[Link]()
Class error (exception):
Class
Value too small error(error):
Class
Value too large error (error):
Number=10
While true :
Try:
i_num=int(input(“enter a number:”))
if i_num<number:
raise
value too small error
elif i_num>number:
raise
value too large error:
break
except value too small error:
print(“this value is too small,try again”)
except value too large error:
print(“this value is too large,try again”)
print(“you guessed it correctly:”)