Write a Programme in Python to find and display the sum of all the values which are ending with '3' from a list ???
Answers
Answer:
example_list = [3, 33, 1, 5, 7, 13, 23, 26]
sum = 0
list_2 = []
for number in example_list:
if "3" in str(number)[-1]:
sum += number
list_2.append(str(number))
print("The numbers are", ", ".join(list_2))
print(f"The sum is {sum}")
Answer: Here is a Python program that finds and displays the sum of all the values in a list that end with the digit '3
Explanation: my_list = [13, 23, 33, 43, 53, 63, 73, 83, 93, 103]
sum = 0
for i in my_list:
if i % 10 == 3:
sum += i
print("The sum of all values ending with 3 is:", sum)
In this example, the list my_list is initialized with some values. Then, a variable sum is initialized to store the total sum of values that end with the digit '3'. The for loop iterates through each element in the list, and checks if the last digit of the element is '3' using the modulus operator (%). If it is, the value is added to the sum variable. Finally, the program prints out the total sum of all values that end with '3'.
You can test this code by running it in a Python environment, like IDLE, and providing your own list of numbers.
Learn more about Python language here- https://brainly.in/question/54541617
Learn more about Python programme here- https://brainly.in/question/16086632
Project code- #SPJ3