![]() |
Nested loops, lists and if statements - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Nested loops, lists and if statements (/thread-2972.html) Pages:
1
2
|
Nested loops, lists and if statements - Liquid_Ocelot - Apr-22-2017 Hey guys I am having a real hard time understanding this question and would just appreciated some clarification on what the instructions are actually asking me to do. I know how to do lists and have a basic understanding of nested loops but executing it is another story I have to make two class lists, one with Maths students and the other with Computer Science students. mathStudents = ['Audrey', 'Ben', 'Julia', 'Paul', 'Gerry', 'Sue', 'Helena', 'Harry', 'Marco', 'Rachel', 'Tina', 'Mark', 'Jackson'] csStudents = ['William', 'Aroha', 'Melissa', 'Sue', 'Ben', 'Audrey', 'Susan', 'Mark', 'Hemi', 'Brendan', 'Paul', 'Barry', 'Julia'] I need to use these lists in nested loops to find out which students are enrolled in both classes and count the total number of students. My output should look like the following: Student: Audrey is enrolled in both classes Student: Ben is enrolled in both classes Student: Julia is enrolled in both classes Student: Paul is enrolled in both classes Student: Sue is enrolled in both classes Student: Mark is enrolled in both classes 6 students are enrolled in Computer Science and Maths RE: Nested loops, lists and if statements - ichabod801 - Apr-22-2017 What have you tried? We prefer helping you fix code you have written to writing code for you. RE: Nested loops, lists and if statements - idontreallywolf - Apr-22-2017 Here's what you need to do: 1. Make a new list called commonClasses = [] 2. Loop trough mathStudents only (because mathStudents and csStudents have the same length).3. inside the loop, check if each student exists in csStudents by using in keyword.4. Loop trough commonClasses and print the names in required form.
RE: Nested loops, lists and if statements - micseydel - Apr-22-2017 (Apr-22-2017, 11:26 AM)idontreallywolf Wrote: if you wish to CHEAT:Speaking as a moderator: please don't do people's homework for them. It's ok to give really heavy hints, but what you posted is far too much. I'd remove it, except that the the OP has Liked it so that would be pointless here. RE: Nested loops, lists and if statements - Liquid_Ocelot - Apr-22-2017 (Apr-22-2017, 09:22 PM)micseydel Wrote:(Apr-22-2017, 11:26 AM)idontreallywolf Wrote: if you wish to CHEAT:Speaking as a moderator: please don't do people's homework for them. It's ok to give really heavy hints, but what you posted is far too much. I'd remove it, except that the the OP has Liked it so that would be pointless here. Yeah I got that. I just needed a clarification on the instructions that were a bit more clearer but I do appreciate the help nonetheless. RE: Nested loops, lists and if statements - smbx33 - Apr-23-2017 Not sharing my solution but will include sample code related to my solution. For reference, I used : Understanding nested list comprehension syntax in Python RE: Nested loops, lists and if statements - Liquid_Ocelot - Apr-23-2017 Hey man I appreciate the help. much clearer now and I'll deff use that reference in future :) RE: Nested loops, lists and if statements - smbx33 - Apr-23-2017 (Apr-23-2017, 04:50 AM)Liquid_Ocelot Wrote: Hey man I appreciate the help. much clearer now and I'll deff use that reference in future :) No problem man! Lets learn together! RE: Nested loops, lists and if statements - idontreallywolf - Apr-23-2017 The moderator just told me not to post code. You should delete it. RE: Nested loops, lists and if statements - smbx33 - Apr-23-2017 I took my code down it doesn't help that you also have a copy of it quoted. Even though I don't think the code provided is doing the work for him per say. |