47.9k views
4 votes
Write a program that prompts the user to enter a string (may contain spaces) and displays its last character. Enter s string: Programming is fun The last character is n

User Nsr
by
5.2k points

1 Answer

3 votes

Answer:

The programming language in Python is as follows:-

#Prompt user for input string

userinput = input("Enter a string: ")

#Print the last character of the input

print("The last character is "+userinput[-1])

#End of Program

Step-by-step explanation:

This line is a comment

#Prompt user for input string

This line prompts user for input

userinput = input("Enter a string: ")

This line is also a comment

#Print the last character of the input

This next line prints the last character of the input string; the last character is defined by the index -1

print("The last character is "+userinput[-1])

User M Mahmud Hasan
by
4.2k points