Using python, write code for problem. The text file Numbers.txt is used and i have put screenshot of data contained in the file. Please also put screenshot of your code.
The file Numbers .txt contains the integers 6, 9, 2, 3, 6, 4 with each integer on a separate line. In Exercises 34 through 42, write a program that uses the file to carry out the task without using lists.
Expert Answer
def main():
“””
Function that prints the last value in the file
“””
# Opening file in read mode
with open(“d:\Python\Numbers.txt”, “r”) as f:
# Iterating over file data
for line in f:
# Stripping new line characters
line = line.strip(“n”);
# Converting to integer and storing in variable
num = int(line);
# Printing number
print(“nn The last number in the file Numbers.txt is %d nn” %(num));
# Calling main function
main();
_______________________________________________________________________________________________
Sample Output:
ScreenShot of Code: