👇 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
Auf dieser Seite können Sie das Online-Video The PERFECT Beginner Coding Exercise in Python | Python Programming Tutorial for Beginners mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Apptato Trivia & Word Games 28 Juni 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 578 Mal angesehen und es wurde von 4 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!