This course provides an introduction to Python scripting. Learn the basics of Python programming and how to use it for scripting tasks.
Course Link: Introduction to Python Scripting
Lab Link: Drawing an ASCII Shape with Python
- Create a file called
asciiShape.py
:touch asciiShape.py
- Make it executable:
chmod +x asciiShape.py
- Insert the instruction for the Python interpreter path at the beginning of the file:
vim asciiShape.py
length = 10
astr = "*"
for i in range(length):
for j in range(length-i):
print(" ", end='')
print(astr)
astr += "**"
length -= 1
space = 1
astrNum = ((length*2)-1)
astr = "*" * astrNum
for i in range(length):
print(" " + space * " " + astr)
astrNum -= 2
astr = "*" * astrNum
space += 1
- Save and exit the file:
- Press Escape
- Type
:wq
- Press Enter
- Execute the file:
python asciiShape.py
Lab Link: Writing Four Functions to Perform Different Arithmetic Operations in Python