Professional Documents
Culture Documents
CLO1 Week 02 Part 2
CLO1 Week 02 Part 2
(CLO1)
Learning Outcomes
• List four of the mostly used high level programming languages
• Recognize four widely used Python packages or libraries
• Convert algorithms from human natural language to computer code
in Python
• Use loop to repeat a block of code
2
High Level Programming Languages
• Computer language also referred to as programming language is a
formal language used to communicate commands to a machine,
typically a computer.
• It is used to create a program to implement a specific algorithm.
3
Example of programming languages
• Java: Used to create programs for mobile phones, web sites, personal
computers, and many other platforms.
• C#, Visual Basic: Used to create programs that run on Microsoft
products.
• Swift: Used to create programs that run on Apple products.
• JavaScript: Used to write games and other programs that run on web
browsers.
• Python: One of the latest computer languages that has unique
capabilities and can run on many devices.
4
How to implement?
• In this course we will be using Python.
• We will use a website called https://repl.it to implement algorithms
5
Why Python Programming Language?
The ability to connect to a wide range of data sources,
integrate with many applications including machine learning,
artificial intelligence, motion graphics, etc.
Package for scientific computing in Python.
t.forward(100)
t.left(90)
7
t.forward(100)
7
Drawing a square in Python - turtle
• Size of each side = 100 dots
Algorithm: • Python code:
• Move pen forward by 100 dots
• Change the angle to the left by 90 degrees
• Move pen forward by 100 dots
• Change the angle to the left by 90 degrees
• Move pen forward by 100 dots
• Change the angle to the left by 90 degrees
• Move pen forward by 100 dots
• Change the angle to the left by 5 degrees
88
Some turtle commands
Method or Required
Command Parameters Description
9 https://trinket.io/docs/colors
Drawing a circle
• Syntax: turtle.circle(radius, extent = None, steps = None)
• radius is the radius of the circle
• extent – an angle – determines which part of the circle is
drawn. If extent is not given, draw the entire circle. If extent
is not a full circle, one endpoint of the arc is the current pen
position.
• steps determines the number of steps to use
• Draw the arc in counterclockwise direction if radius is
positive, otherwise in clockwise direction.
10
10
Drawing a circle
• import turtle as t
• t.circle(50) draw a circle
with a radius of 50 dots.
• t.circle(50, 180) draw a ½
circle with a radius of 50 dots.
• t.circle(50, 180, 4) draw a
½ circle with a radius of 50
dots, 4 steps.
11
11
fillcolor(colorName)
• Fills a closed shape with a color
• Should be used with begin_fill( ) and end_fill( )
• Example:
t.fillcolor("red")
t.begin_fill( )
t.circle(50)
t.end_fill( )
12
12
Exercise
• Draw the following shapes:
13
13