26.6k views
3 votes
Write a program to do the following:

1. ask the user to enter first sentence and save in string variable.
2. ask the user to enter second sentence and save in another string variable.
3. Compare to check if the two sentences are equal or not (ignoring the case of letters):
4. If the result true
a. Display "They are equal" to the user
b. Find the first appearance (the position/index) of letter 'a' in the first sentence.
5. Else if result false
a. Display "They are not equal" to the user
b. Find the character at position/index 3 in the second sentence.

1 Answer

3 votes

Final answer:

This is a Python program that prompts the user to enter two sentences, compares them for equality (ignoring case), and performs different actions based on the result. It prints out whether the sentences are equal or not and finds the first appearance of the letter 'a' in the first sentence if they are equal, or finds the character at position 3 in the second sentence if they are not equal.

Step-by-step explanation:

Python Program

Here's a Python program that will do the steps you mentioned:

# 1. ask the user to enter first sentence and save in string variable
first_sentence = input('Enter the first sentence: ')

# 2. ask the user to enter second sentence and save in another string variable
second_sentence = input('Enter the second sentence: ')

# 3. Compare to check if the two sentences are equal or not
if first_sentence.lower() == second_sentence.lower():
# 4a. Display 'They are equal' to the user
print('They are equal')

#4b. Find the first appearance (the position/index) of letter 'a' in the first sentence
first_a_index = first_sentence.lower().index('a')
print('The first appearance of letter a in the first sentence is at index:', first_a_index)
else:
# 5a. Display 'They are not equal' to the user
print('They are not equal')

# 5b. Find the character at position/index 3 in the second sentence
third_character = second_sentence[2]
print('The character at position 3 in the second sentence is:', third_character)
User Syamesh K
by
8.7k points