Please write a code for the following classwork assignment:
Create a program that:
- Asks the user for the name of a file and reads it in.
- Asks the user to enter a series of numbers, and when done enters a period '.'.
- The program should write the numbers entered by the user to a file.
- The program should close the file and then open it again for reading. The program should then read all numbers from the file, using a while loop, and find their average. Finally, it should print the average to the screen.
- Repeat the program, but this time using a for loop for reading.
- Make sure to handle the case where the user immediately enters a '.' without entering any numbers when calculating the average.