Python nested loops ➿

preview_player
Показать описание
python nested loops tutorial example explained

#python #nested #loops

# nested loops = The "inner loop" will finish all of it's iterations before
# finishing one iteration of the "outer loop"

rows = int(input("How many rows?: "))
columns = int(input("How many columns?: "))
symbol = input("Enter a symbol to use: ")

for i in range(rows):
for j in range(columns):
print(symbol, end="")
print()
––––––––––––––––––––––––––––––
Creative Commons — Attribution-ShareAlike 3.0 Unported— CC BY-SA 3.0
––––––––––––––––––––––––––––––
Рекомендации по теме
Комментарии
Автор

# nested loops = The "inner loop" will finish all of it's iterations before
# finishing one iteration of the "outer loop"

rows = int(input("How many rows?: "))
columns = int(input("How many columns?: "))
symbol = input("Enter a symbol to use: ")

for i in range(rows):
for j in range(columns):
print(symbol, end="")
print()

BroCodez
Автор

I found this a bit tricky to understand but think Im now there. Ive added comments to try help other people, but I'm also willing to accept I might be wrong.

# nested loop = is the general concept of having one loop inside another loop.
# nested loop = the 'inner loop' will finish all of its iterations before finishing the iteration of the 'outer loop'
# To best demonstrate this we will create a program to draw a rectangle made out of a symbol of our choice.
# We need to set a width, height and the symbol of choice.

rows = int(input("How many rows?: "))
columns = int(input("How many Columns: "))
symbol = input('What symbol would you like to use?: ')

# Now it's time for the nested loop. We're going to create an outer for loop and an inner for loop.
# The outer for loop will be in charge of the rows and the inner the columns.
for i in range(rows):
for j in range(columns): # This loop will be iterated first.
print(symbol, end="") # This will print the symbol once every iteration. Will iterate 'columns' times.
# After we use a print statement the console will start a new line. We don't want this when defining the columns so we add "end=".
print() # This will print the symbol once every iteration. Will iterate 'rows' times.
# We do want a new line when defining rows. So we add a print statement that is empty to initiate a new row per iteration.

leachyboi
Автор

by far the most confusing one, might have to look up the docs on this ngl

cybrlol
Автор

This dude makes everything so easy to understand, keep up the great work

elliotradley
Автор

Your videos lectures are sincerely good and very easy to understand. You made me love learning Python! My two thumbs up for you Bro! Keep it up! Thank you very much!

Analyst
Автор

Finally!
After practicing and Watching over and over.

rotes
Автор

Started programming for about 2 years ago and kind of lost the spark due to boring material. Decided to really do this now and must say that the content of your videos are easy to understand and inspiring!

johankarlsson
Автор

Quick and straight to the point. Thanks!

LittleMew
Автор

Great easy to follow tutorials. 👍🏻👍🏻👍🏻

varunwind
Автор

2 lines code(god command lines) was amazing, it helped me a lot, tks Bro

gianhat
Автор

how does writing print() with nothing in the parenthesis work? also typing end after print is a new one on me too. Do we always writing it = "" like that? what would happen if we put something in the quotes?

ClickDecision
Автор

This video helped me with homework on zybook. Thank you!!!!

a_pharmtechwhocodesanddanc
Автор

for i in range(row):
print(sym*col)

cykachu
Автор

It finally makes some sense to me thanks keep it up

nope
Автор

alternative code :
rows=int(input("HOE MANY ROWS DO YOU WANT :"))
columns=int(input("HOW MANY COLUMNS DO YOU WANT"))
symbol=input("enter your symbol u need :")
A=symbol*columns
for i in range(rows):
print(A)

thegamer
Автор

actually this whole code is confusing to me lol. can you break it down for me step by step as to how this is working?

ClickDecision
Автор

I really wonder what does print() with nothing inside mean ?

quochuyluong
Автор

Hmmm, I don't understand the last line print()

LeTrungKiena-xcfn
Автор

can someone tell me what is the function of the 'print()' i could'nt understand the reason behind it

lightheartedsiegward