-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19.py
More file actions
40 lines (35 loc) · 969 Bytes
/
19.py
File metadata and controls
40 lines (35 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# example 1
try:
age=int(input("enter the age:"))
if age < 0:
print('age cannot be negative')
else:
years_left=100-age
if years_left>0:
print(f"you will be 100 years old in {years_left} years.")
elif years_left==0:
print("your already 100 years old.")
else:
print("your already over 100 years")
except ValueError:
print("Invalid input , please enter a valid input")
# example 2
try:
a=int(input("enter a value:"))
b=int(input("enter b value:"))
c=a/b
print("sucsess",c)
except ZeroDivisionError:
print("zero division errror")
except ValueError:
print("please enter a valid input")
#example 3
try:
filename=input('enter a file name:')
file=open(filename,'r')
content=file.read()
file.close()
except FileNotFoundError:
print('Error File does not exist.')
finally:
print("program end")