r/learnprogramming • u/Pompomcry • Jul 01 '22
Tutorial For loop NSFW
I’m having issues with the for loop. The assignment I’ve been given (due in 3 hours :’() is asking me to use a for loop to iterate over an existing list and display the list(there’s more but this is where I’m stuck right now)It’s a uni assignment and lord have mercy I need help ! Please anyone !!
Edit: I’m sorry for the lack of info it was 3 am and The dread of the deadline was starting to hit. Also I’m new
The language is python, the task is to create 2 functions and basic user interaction to book a theatre ticket. I’ve been given the theatre variable already in the program, all I have to do is create a “displayseats” and “bookASeat” function. The displayseats variable is required to iterate over the theatre list of lists and display whether or not a seat is booked using the letter ‘X’ or available using the letter ‘O’- specifically says not to use 0. Also says not to change the values in the ‘theatre’ list of lists in this function. This is task 1…… I think the fear of failing has caused my brain to go completely blank
Edit2: this subreddit doesn’t allow images :(( Basically the theatre is a bunch of O’s on the program but on my spec it’s A-F down and 1-12 across with A1-A3 being no seats and A10-A12 being no seats (same for B1-B3 and B10 and B12). Seats E&F are delux seats so I’m not sure if I should maybe like have a different function or code for that? I’m not sure what I’m doing at all. I’m reaching zen at this point ( ̄∇ ̄)
1
u/bravosix99 Jul 01 '22
Basically, a for loop(or just running through a loop in general), is basically going through something. In this case, you're just going through a list. But depending on the language, you'll do this differently(i''ll do it in java as an example)
for(int i = 0;i< array.length;i++){
System.out.println(arraylist[i]);
}
the variable(left) is the point where you start in the list, the length part (middle) is going through the list until you reach its size(so if its 5 things in the list, you should see 5 things), and the i++(right), goes to the next item in your array.
Simple as that.^
However(and as stated by some comments below), it would be more helpful if you told the Language and any code you tried so far..
Hope this helps!