satya

Tuesday, October 6, 2020

Program-9

                                                                             Program-9

Write a program that asks the user to enter two strings of the same length. The program should then check to see if the strings are of the same length. If they are not, the program should print an appropriate message and exit. If they are of the same length, the program should alternate the characters of the two strings. For example, if the user enters abcde and ABCDE the program should print out AaBbCcDdEe.


s1=input("enter the string1:")

s2=input("enter the string2:")

r=''

if(len(s1)==len(s2)):

    print('Two strings are same length')

    for i in range(len(s1)):

        r=r+(s2[i]+s1[i])

    print(r)

else:

    print("Two strings  are different")

OUTPUT:
>>>
== RESTART: C:\Users\HI\Desktop\prog\s2.py =======
enter the string1:abcd

enter the string2:ABCD

Two strings are same length

AaBbCcDd

>>> 
= RESTART: C:\Users\HI\Desktop\prog\s2.py
enter the string1:cdf
enter the string2:ABCdf
Two strings  are different

>>> 

No comments:

Post a Comment

Program 30

                                                                         Program 30 Write a Python class to implement pow(x, n). class Pow1:...