111k views
3 votes
Assume that name is a variable of type String that has been assigned a value.Write an expression whose value is a String containing the last character of the value of name.So if the value of name were "Smith", the expression's value would be "h".

1 Answer

5 votes

Answer:

#read value of name

name=input("Enter name:")

#find and ptint the last character of the string

print("last character of string is:",name[-1])

Step-by-step explanation:

Read a string from user and assign it to variable "name".Find its last character as "name[-1]". Since name is character array,so name[-1] will give the last character of the array.

Output:

Enter name:Smith

last character of string is: h

User Leandrodemarco
by
5.2k points