Classwork 03-03-2022 (W5 Part-2)

 avatar
unknown
text
3 years ago
1.2 kB
89
Indexable
1) Create a file called "sample-cars.txt" in the project folder. Edit the
   file & add the following car names:

   Tesla
   Audi
   BMW
   Electra
   Cadillac
   Infiniti
   Nissan

   Write a program to read the file & print it out.


2) Extend the leap year program from last class by asking whether the
   user would like to save that information. If the user agrees,
   save output to a file named "leap-year.txt" after displaying it.
   Try to maintain the same formatted output in the text file.

   Demo:
   =====
   > Start year: 1900
   > End year:   2100
   > Save information? (y/n): y
   
   1904 1908 1912 1916 1920 1924 1928
   1932 1936 1940 1944 1948 1952 1956
   1960 1964 1968 1972 1976 1980 1984
   1988 1992 1996 2004 2008 2012 2016
   2020 2024 2028 2032 2036 2040 2044
   2048 2052 2056 2060 2064 2068 2072
   2076 2080 2084 2088 2092 2096
   
   $ cat leap-year.txt
   1904 1908 1912 1916 1920 1924 1928
   1932 1936 1940 1944 1948 1952 1956
   1960 1964 1968 1972 1976 1980 1984
   1988 1992 1996 2004 2008 2012 2016
   2020 2024 2028 2032 2036 2040 2044
   2048 2052 2056 2060 2064 2068 2072
   2076 2080 2084 2088 2092 2096 


Editor is loading...