The last element of list using a while loop

In this program, we will print the last element of list using a while loop.

Steps to solve the program
  1. Take a list as input, create a variable and assign its value equal to 0.
  2. While the value of the variable is less than the length of the list add 1 to the variable.
  3. At the end of the loop, the variable’s value is equal to the length of the list.
  4. Print the last element of the list with the help of that variable and indexing.
				
					list1 = ["s","q","a","t","o","o","l","s"]
count = 0

while count<len(list1):
    count += 1
    a = count

print("Last element of the list: ",list1[a-1])
				
			
				
					Last element of the list:  s
				
			

Output :

add special characters in an empty list from a given list

print 1-10 natural numbers but it should stop when the number is 6

Leave a Comment