This is a Python Program to take in two strings and display the larger string without using built-in functions.
The program takes in two strings and display the larger string without using built-in function.
1. Take in two strings from the user and store it in separate variables.
2. Initialize the two count variables to zero.
3. Use a for loop to traverse through the characters in the string and increment the count variables each time a character is encountered.
4. Compare the count variables of both the strings.
5. Print the larger string.
6. Exit.
Here is source code of the Python Program to take in two strings and display the larger string without using built-in functions. The program output is also shown below.
string1=raw_input("Enter first string:") string2=raw_input("Enter second string:") count1=0 count2=0 for i in string1: count1=count1+1 for j in string2: count2=count2+1 if(count1<count2): print("Larger string is:") print(string2) elif(count1==count2): print("Both strings are equal.") else: print("Larger string is:") print(string1)
1. User must enter two strings and store it in separate variables.
2. The count variables are initialized to zero.
3. The for loop is used to traverse through the characters in the strings.
4. The count variables are incremented each time a character is encountered.
6. The count variables are then compared and the larger string is printed.
Case 1: Enter first string:Bangalore Enter second string:Delhi Larger string is: Bangalore Case 2: Enter first string:Ball Enter second string:Apple Larger string is: Apple
No comments:
Post a Comment