string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")
if string1 == string2:
print("The strings are the same.")
else:
print("The strings are different.")
#source code --> clcoding.com
Code Explanation:
Taking User Input
string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")
The program prompts the user to enter two strings.
The input() function is used to take user input as strings.
The values entered by the user are stored in the variables string1 and string2.
Comparing the Two Strings (Case-Sensitive)
if string1 == string2:
The == comparison operator is used to check whether the two strings are identical.
This comparison is case-sensitive, meaning "Hello" and "hello" are considered different because of the uppercase "H".
Printing the Result
print("The strings are the same.")
else:
print("The strings are different.")
If the strings are exactly the same, the program prints:
"The strings are the same."
Otherwise, it prints:
"The strings are different."
0 Comments:
Post a Comment