Question:5
Python script to calculate the sum of two non –ve numbers
Sol:
def sum_nos(x,y): #print(x,y) x=x-1 y=y+1 if(x==0): print("sum = ",y) else: sum_nos(x,y) while True: n1=int(input("Enter 1st no ")) n2=int(input("Enter 2nd no ")) if(n1<0 or n2<0): print("numbers should not be -ve") else: sum_nos(n1,n2) ch=input("Like to cont ... (y/n) ") if(ch=="y" or ch=="Y"): continue else: break
Output:
Enter 1st no 10
Enter 2nd no 20
sum = 30
Like to cont … (y/n) y
Enter 1st no 2
Enter 2nd no 6
sum = 8
Like to cont … (y/n) y
Enter 1st no 32
Enter 2nd no 6
sum = 38
Like to cont … (y/n) n
>>>