Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
The list ["4", "x", "7", "3"] holds texts. Convert each one to a whole number, skip the ones that fail, and add up the good ones.
try inside a loop lets the loop go on after a bad value.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. A loop over the texts. In each round, try to convert and append to a new list. If a ValueError happens, show skipping and the text.
The good values are , and . The text x is skipped. The sum is .
Log in to join the discussion.
Loading…