Question: python Imagine you have a text file where each line consists of a symbol, a space, and an integer. The possible symbols are, and Here's
Imagine you have a text file where each line consists of a symbol, a space, and an integer. The possible symbols are, and Here's an example of what the file might look like: * 12 #8 # 23 @ 17 How Wrie a function that satisfies the following specifications: Your function should take one argument: the name of a text file whose contents are formatted as described above. You can assume that the name of the file is a string and that the file actually exists. . Your function should use a with statement to open the file from the argument for reading. Your function should read each line in the file. Your function should return (not print! the sum of all numbers from the file that have a in front of them. In the case of the example file above, the sum would be 31. If no numbers in the file have a # in front of them, your function should return 0. Your program should not import any modules or include any code outside of your function. You do not need to write any docstrings. You do not need to follow normal course style conventions regarding variable names or the length of lines of code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
