#23 Python Tutorial for Beginners | Printing Patterns in Python

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

In this lecture we will learn:
- How to implement the logic for pattern printing?
- Pattern printing through python
- Print the pattern of a square
- Print the pattern of the right triangle and reverse right-triangle
- Different approaches to printing a pattern

#1
- Pattern printing improves logical thinking capability.
- Programming is all about solving the problem, we have to understand the problem statement and wrote code for it.
- A pattern can be printed in many ways.
- We can print multiple hashes(#) in a single statement as a string.
- If you are allowed to print only hash in a statement at a time, then you have to write the same print statement multiple times.
- On writing a statement multiple times, it will give an output in a column.
- To convert a column output into a row format, we can use the end=" "parameter in every statement.
- To will restrict the cursor to move on a new line and hashes(#) will be printed in a single row.

#2
- Instead of writing the same code multiple times, we can use a for a loop.
- For a range(n) in a for loop, it will start from 0 and end at (n-1).
- We can use two loops, for printing two rows separated by a new line.
- For printing multiple rows, we have to write the same for loop code repeatedly.
- So, we can write the above for loop block inside another outer loop.
- In nested loops, an outer loop contains a variable that represents the number of rows and an inner loop contains a variable that represents the number of columns.

#3
- We can apply the concept to different patterns in a similar way.
e.g., for printing a right -triangle, we can restrict the inner loop till the value of a number of rows.
- For the reverse of the right triangle, we can restrict the inner loop till (n-i), where i is the number of rows.

Python Tutorial to learn Python programming with examples

In this video we will see:
- Printing patterns
- Using loop
- For loop

Editing Monitors :

Editing Laptop :

Mics

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

I can bet that no courses can be better then this even that is paid. I have purchased almost 5-6 courses form udemy but i couldn't find anyone better then this. A huge thanks to Mr Naveen Reddy Sir for providing this awesome courses and sir we really appreciate you for providing us such valuable resources.

AmarjeetKumar-doiz
Автор

str1='ABCD'
str2='PQR'
for i in range(4):
print(str1[ : i+1 ] + str2[ i : ])

vijaychaurasiya
Автор

that man needs much more recognition, seriously i learned from this guy in a couple of months what i learned from college in one academic year, not just in python, but his other topics and his logic

panakitikos
Автор

1.for i in range(1, 5):
2. for j in range(i, 5):
3. print( j, end=" ")
4. print()

nikhilpn
Автор

Awesome...
Better than paid courses...

rizwanshaikh
Автор

Answers for 1st and 2nd:
for i in range(5):
for a in range(4-i):
print(a+1+i, end='')
print()
😑2nd one:
a, b="ABCD", "PQR"
for i in range(4):
print(a[:i+1]+b[i:])
Thank you SIR 😊

ashokreddy
Автор

1)

for i in range(4):
for j in range(4-i):
print (i+j+1, end=' ')

print()

AnkushMalode
Автор

1).
for i in range(4):
for j in range(i+1, 5):
print(j, end="")
print()
2).
s1="ABCD"
s2="PQR"
for i in range(4):
print(s1[0:i+1]+s2[i:])

sarthakagrawal
Автор

#Solution for 2nd problem
for i in range(4):
for j in range(4):
if(i<j):
print(chr(65+14+j), end=" ")
else :
print(chr(65+j), end=" ")
print()

ranjeet_
Автор

1)
for i in range(1, 6):
for j in range(i, 5):
print(j, end="")
print()
2)
s1="ABCD"
s2="PQR"
l=len(s1)
for i in range(0, 4):
for j in range(i+1):
print(s1[j], end="")
for k in range(i, 3):
print(s2[k], end="")
print()

DarkKnight-dcgr
Автор

Great Teacher I got in YouTube, the best part you have mention "we don't teach we educate" it is actual true, I really enjoy your videos, Thanks for teaching

nishantchandraazad
Автор

I've watched a 6 hour course and used sololearn and this was never properly explained. You explained perfectly. I commend you

brodycates
Автор

Dear Sir. This is a very valuable series. I got the same result with below code.
for i in range(4, 0, -1): # starting each row from the heighest size
for j in range(i): # Printing each column inside each row according to row size
print("#", end="")
print() # Printing a new line to start a new row
Please do more stuff like this. Respect from a

thilinasenadheera
Автор

The reason for learning this explained in 45 seconds. This is hat I have found gold with Navin's videos, in addition the the solid walk through.

mrjh
Автор

Trust me it's much better than any paid course's . Truely appreciable work. Thanks sir for giving such type of knowledge 🙂

ritiksingh
Автор

For the reverse I used range and gotten the same result which is pretty cool. Code:
for i in range(5, 0, -1):
for j in range(i):
print("# ", end="")
print()

adriaanmeij
Автор

1st pattern:==>
for i in range(1, 5):
for j in range(1, 5):
k=i+j-1
if k>4:
print("", end="")
else:
print(k, end="")
print()
2nd pattern:==>
x='ABCD'
y='PQR'
for i in range(1, 5):
print(x[:i]+y[i-1:])

PiyushSharma-hyej
Автор

I'm a beginner.I liked the way he teaches. Started watching his videos in the morning 11 a.m and now reached 21st video by this time on the very same day. wonderful job sir.Nobody can teach the way he teaches.

prathikkundaragi
Автор

#1
For i in range (1, 5):
For j in range (i, 5):
Print(j, end="")
Print()

#2
a="ABCD"
b="PQR"
for i in range (4):
For j in range (3):
Print(a[0:i+1], end="")
Print(b[i:j+3], end="")
Break
Print()

anusreeanoop
Автор

A ="ABCDPQR"
for i in range(4):
for j in range(7):
if j>i and j<i+4:
continue
else:
print(A[j], end =" ")
print()

amyamy