Apr-16-2021, 08:12 AM
Lets start from the beginning.
You have given two things.
1. Array with four items in it.
2. A integer variables.
The homework problem said print every element in array x 6 times. Then print something else.
First build a for else loop that refer to line of sanity variable.
#For loop with else while
Then build a separate loop that prints all items in array.
If you can build those loops, then try to nest one for loop with in another.
When I saw this problem, I didn’t know this. But I know python have some loop functions. So visited here to look up.
https://www.w3schools.com/python/python_for_loops.asp
Learn to break down one big problem to smaller chucks and then solve the parts.
The range() Function
This is how to use integer variable in for loop.
Else in For Loop
This is how you break out of loop.
Nested Loops
This is how you nest one for loop with another.
Build it in order separately. After that combine.
You have given two things.
1. Array with four items in it.
2. A integer variables.
The homework problem said print every element in array x 6 times. Then print something else.
First build a for else loop that refer to line of sanity variable.
#For loop with else while
Then build a separate loop that prints all items in array.
If you can build those loops, then try to nest one for loop with in another.
When I saw this problem, I didn’t know this. But I know python have some loop functions. So visited here to look up.
https://www.w3schools.com/python/python_for_loops.asp
Learn to break down one big problem to smaller chucks and then solve the parts.
The range() Function
This is how to use integer variable in for loop.
Else in For Loop
This is how you break out of loop.
Nested Loops
This is how you nest one for loop with another.
Build it in order separately. After that combine.