From 819313a5d01e8e090b41f6504806ad61b1fe6681 Mon Sep 17 00:00:00 2001 From: Ratnesh Kumar <142919875+16ratneshkumar@users.noreply.github.com> Date: Mon, 29 Jul 2024 22:17:58 +0530 Subject: [PATCH] Add exception handling --- Calculate resistance.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Calculate resistance.py b/Calculate resistance.py index 10c7a5ad3e2..ee6f10319a1 100644 --- a/Calculate resistance.py +++ b/Calculate resistance.py @@ -1,12 +1,16 @@ -def res(R1, R2): - sum = R1 + R2 - if (option =="series"): - return sum - else: - return (R1 * R2)/(R1 + R2) -Resistance1 = int(input("Enter R1 : ")) -Resistance2 = int(input("Enter R2 : ")) -option = str(input("Enter series or parallel :")) -print("\n") -R = res(Resistance1,Resistance2 ) -print("The total resistance is", R) +def res(R1, R2): + sum = R1 + R2 + if option =="series": + return sum + elif option =="parallel" : + return (R1 * R2)/sum + return 0 +Resistance1 = int(input("Enter R1 : ")) +Resistance2 = int(input("Enter R2 : ")) +option = input("Enter series or parallel :") +print("\n") +R = res(Resistance1,Resistance2 ) +if R==0: + print('Wrong Input!!' ) +else: + print("The total resistance is", R)