Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+4 votes

Confused on where to start on Q5, i feel like i need to:

  1. use an if statement to determine which file to read? option 1 or 2
  2. use a loop somehow to calculate the grades, and output A-F accordingly? or
  3. use a loop somehow to determine the grade average?

any tips appreciated ^^

asked in CSC201 Spring 2021 by (1 point)

1 Answer

+3 votes

Instead of using an if statement to determine what file to read, you should ask the user for an input, and have a variable that stores the input file, like

fileName = input("~~~")

And then you have to open the file, which looks like

inFile = open(filename, "r")

The "r" is what tells the code to read the file, other letters do other things.

And then for actually reading the file, you can loop through the file like this:

for line in inFile:

And each loop will read the next line and store it as "line".
Youll want to use .split() to turn the read lines into a list, and use indexing [] and several if/elif statements to complete the problem.

answered by (1 point)
+1

Thank you tons Furby. Sometimes getting started is the hardest part!

...