-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexeption_handling.py
More file actions
78 lines (48 loc) · 1.51 KB
/
exeption_handling.py
File metadata and controls
78 lines (48 loc) · 1.51 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""import os,time,shutil
import shutil
print("OS Name:" ,os.name)
print(os.getcwd())
print(os.listdir("."))
print(os.listdir(".."))"""
"""try:
a=int(input("Enter number: "))
b=int(input("Enter another number: "))
print(a/b)
except ZeroDivisionError:
print("Division by zero")
except ValueError:
print("Invalid number entered ")"""
"""try:
x=int(input("Enter number: "))
except ValueError:
print("Invalid input")
else:
print("Square =",x*x)"""
"""#1
numbers=[10,20,30,40,50]
try:
user_input=input("enter an index(0-4) to see the number between 0 and 4.")
index=int(user_input)
print(f"The value at index{index} is:{numbers[index]}")
except IndexError:
print(f"Error:The index{index} is out of range.please enter a number betweem 0 to 4.")
except ValueError:
print("Error:invalid input please enter valid number. ")"""
#2
def add_values():
val1 =input("enter the first value: ")
val2 =input("enter the second value: ")
try:
result = float(val1)+ float(val2)
print(f"The sum is:{result}")
except ValueError:
print("Error:Incompatible data types.please enter numeric values only.")
add_values()
#3
total_sum=0
print("enter numbers to add the up.pressclt+c to stop and see the final sum.")
try:
while True:
user_input = input("enter a number: ")
try:
total_sum+=float(user_input)