The PERFECT Beginner Coding Exercise in Python | Python Programming Tutorial for Beginners

Pubblicato il: 28 giugno 2019
sul canale di: Apptato Trivia & Word Games
578
4

👇 Solution Code provided below

This is the perfect beginner coding exercise in Python that will get you familiar with coding fast! A Python Programming Tutorial for Beginners!

You can follow along with any online Python 3 compiler. No installation required! Links are in the description below.

Subscribe to Apptato for more Python Tutorial for Beginners!

Print the following shapes with width n (Where n is an integer greater than or equal to 0)

A line, square, right triangle, pyramid, diamond


💻 Solution Code:

def printLine(n):
print("x"*n)
printLine(5)

def printSquare(n):
for x in range(n):
printLine(n)
printSquare(5)

def printTriangle(n):
for x in range(n):
printLine(x+1)
printTriangle(5)

def printPyramid(n):
for x in range(n):
print(" "*(n-x-1) + "x "*(x+1))
printPyramid(5)

def printDiamond(n):
printPyramid(n)
for x in range(n):
print(" "*(x+1) + "x "*(n-1-x))
printDiamond(5)


💻 Output:

#1 Line
xxxxx

#2 Square
xxxxx
xxxxx
xxxxx
xxxxx
xxxxx

#3 Right Triangle
x
xx
xxx
xxxx
xxxxx

#4 Pyramid
x
x x
x x x
x x x x
x x x x x

#5 Diamond
x
x x
x x x
x x x x
x x x x x
x x x x
x x x
x x
x

💻 Reference Code:

#Quick Python 3 Refresher

#Print
print("Hello World")
print("Hello","World")
print("Hello" + " World")

#For Loop
for x in range(5):
print(x)

#Functions
def myFunction(n):
print("My Function:")
for x in range(n):
print(x)

myFunction(3)


🔗 Links:

Online Compiler:
https://www.onlinegdb.com/online_pyth...

Apptato Links:
Website: http://www.apptato.com
YouTube:    / apptato  
Twitter:   / apptato  
Facebook:   / apptato  
Instagram:   / apptato  

#CodingTutorial #pythontutorialforbeginners #PythonForBeginners


In questa pagina del sito puoi guardare il video online The PERFECT Beginner Coding Exercise in Python | Python Programming Tutorial for Beginners della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Apptato Trivia & Word Games 28 giugno 2019, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 578 volte e gli è piaciuto 4 spettatori. Buona visione!