Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
comparing two lists
#13
Some observations:

- if feasible you can outsmart your teacher by defining of your own zip function and taking advantage code snippet provided by ichabod801 earlier in this thread. Python documentation about built-in function zip() contains code how zip functionality is implemented.

- I suggest to open files differently, using with statement (no need to close file + some other benefits):

>>> with open("test.txt" , "r") as f:
...     student_answers = []
...     for line in f:
...         student_answers.append(line.strip('\n')) 
If you have learnt list comprehension then you could have:

>>> with open('test.txt', 'r') as f:
...     student_answers = [line.strip('\n') for line in f]
Or even:

>>> student_answers = [line.strip('\n') for line in open('test.txt', 'r')]
- if you are using main() then you could move reading the student answers into separate function as well as returning number of correct answers and list of incorrect answers. It can improve readability of your code.

- in printing I recommend using f-strings or .format method. They are 'modern' and subjectively more readable

- You have hardcoded 20 to determine number of incorrect answers (row 34). You could use len(CORRECT_ANSWERS) - correct_answers. This way your message will be correct if number of questions changes. Same principle can probably applied to code on row 29 where it seems that 75% is required to pass.

- maybe you should use different name for number of student correct answers; currently there is possibility to mix up 'CORRECT_ANSWERS' and 'correct_answers'

- row 35 you will print out list with square brackets. You could print out values without square brackets and separated with commas: print('Your message', ', '.join([str(x) for x in incorrect_num])
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
comparing two lists - by Siylo - Jan-21-2019, 07:20 PM
RE: comparing two lists - by perfringo - Jan-21-2019, 07:29 PM
RE: comparing two lists - by Siylo - Jan-21-2019, 07:31 PM
RE: comparing two lists - by nilamo - Jan-21-2019, 09:23 PM
RE: comparing two lists - by ichabod801 - Jan-21-2019, 08:36 PM
RE: comparing two lists - by Siylo - Jan-21-2019, 08:52 PM
RE: comparing two lists - by ichabod801 - Jan-21-2019, 09:18 PM
RE: comparing two lists - by Siylo - Jan-21-2019, 09:27 PM
RE: comparing two lists - by ichabod801 - Jan-21-2019, 09:51 PM
RE: comparing two lists - by Siylo - Jan-21-2019, 09:58 PM
RE: comparing two lists - by ichabod801 - Jan-21-2019, 10:19 PM
RE: comparing two lists - by Siylo - Jan-21-2019, 10:59 PM
RE: comparing two lists - by perfringo - Jan-22-2019, 08:12 AM
RE: comparing two lists - by Siylo - Jan-22-2019, 06:56 PM
RE: comparing two lists - by ichabod801 - Jan-22-2019, 07:19 PM
RE: comparing two lists - by Siylo - Jan-22-2019, 09:03 PM
RE: comparing two lists - by nilamo - Jan-22-2019, 09:25 PM
RE: comparing two lists - by Siylo - Jan-22-2019, 10:01 PM
RE: comparing two lists - by Siylo - Jan-22-2019, 11:38 PM
RE: comparing two lists - by ichabod801 - Jan-23-2019, 02:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Comparing 2 lists BerryK 4 4,634 Apr-15-2017, 09:46 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020