Q. Write a program that does the following:

(i) Take two inputs: the first, an integer and the second, a string.

(ii) from the input string extract all the digits in the order they occurred, from the string.

(a) if no digits occur , set the extracted digit to 0.

(iii) add the integer input and digits extracted from the string together  as integer.

(iv) print a string of the form:

“integer _input + string _ digits = sum”


You can understand by Watching video :-



Answer :-

num = int(input("Enter an integer :-"))
word = input("Enter a string :-")
digit = ""
for i in word :
    if i.isdigit() :
        digit += i
if digit== "" :
    digit = 0
else :
    digit = int(digit)
print(num, ",", word, "->", num, "+", digit, "=", num + digit )

Output :-

Enter an integer :-55
Enter a string :-PathWalla
55 , PathWalla -> 55 + 0 = 55

>>>


Enter an integer :-100
Enter a string :-Path1234
100 , Path1234 -> 100 + 1234 = 1334

>>>

6 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post