From 69f8766e388cba10774ce017da47f20837e78bf0 Mon Sep 17 00:00:00 2001 From: utkarshasingh12 <70209603+utkarshasingh12@users.noreply.github.com> Date: Sat, 31 Oct 2020 01:44:02 +0530 Subject: [PATCH] Create python code program to create a list where elements are enter by a user separated by comma then find sum of first and last number of the list using exception handling. --- python code | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 python code diff --git a/python code b/python code new file mode 100644 index 0000000..7cefc63 --- /dev/null +++ b/python code @@ -0,0 +1,18 @@ +#program to create a list where elements are enter by a user separated by comma then find sum of first and last +#number of the list using exception handling. + +inp=input("enter a number") +lst=inp.split(",") +li=[] +for i in lst: + li.append(int(i)) +print("list is:",li) +try: + sum=li[0]+li[len(li)-1] + print(sum) +except TypeError: + print("enter corerct operation") +except valueError: + print("enter the correct type") +else: + print("successfully executed")