SAS Week 1 Python Primer
SAS Week 1 Python Primer
Week 1 – Day 3
Information Technology Department
Materials
Computer, Student Activity Sheet, PPT
PYTHON PRIMER
References
Intended Learning Outcomes Beginning Java Data Structures and Algorithms by James
Cutajar
At the end of the lesson, you should be able to:
Data Structures for Gujarat Technological University by
Create programs using Python programming language Reema Thareja
Data Structure and Algorithmic Thinking with Python by
Narasimha Karumanchi
SDG Integration
SDG # 4 – Quality Education (Ensure inclusive and equitable quality
education and promote life-long learning opportunities for all
SDG # 5 – Gender Equality (Achieve gender equality and empower all
women)
SDG # 9 – Innovation and Infrastructure (Build resilient infrastructure,
promote inclusive and sustainable industrialization and foster innovation
Survey the students what programming language they have mastered so far (Poll Survey)
Points to Remember
PYTHON PRIMER
Spyder: Python IDE for Absolute Beginners (Need to install Anaconda Distribution)
Spyder is an IDE aimed at mainly scientific researchers, data analysts, or those involved in scientific package
creation. Spyder’s developers have designed it to be the ideal tool for developing Python applications, and
Spyder itself has been created using Python.
Console: When we run our code(we will see how to do it in a while), the outputs/errors from our code will be
displayed here. We can also give single-line commands in the console for instant output. There are many more
important uses of it. We will discuss them later.
Variable Explorer
You can see all the variables created by running your code in this variable explorer. It shows you the Name,
Type, Size, and some values of the variable. you can also search for a variable by its name, erase single or all
the variables at a time.
HANDS – ON ACTIVITY: Take s screenshot of the Python script and the sample output.
Submit it in PDF via GClassroom
Exercise#1
Create a program that asks the user to enter their name and their age. Print out a message addressed to
them that tells them the year that they will turn 100 years.
Exercise #2
A store sells baking products at P650 and pastries at P350. Write a program that inputs the number of
baking products and pastries bought and output the bill. Assume that your program will ask the buyer to
input amount to pay. Output the change to be given by the buyer.
Exercise #3
Make a python program that will accept to integers and display the sum, difference , product , quotient and
average.
Exercise #4
Make a program that asks the user for a number. Depending on whethere the number is even or odd,
printout an appropriate message to the user.
Exercise #5
Take a list, say for example this one: a = [1, 3, 5, 343, 56, 78, 34, 12, 90]. Write a program that print outs
all the elements of the list that are less than 30.
Exercise #6
Create a program that askes the user for a number and then prints out a list of all the divisors of that
number.
Exercise #7
Take a list, say for example these two:
A= [1, 2, 3, 6, 12, 55, 23, 78, 89, 1]
B= [ 1, 2, 3, 4, 5, 6, 12, 24, 32]
Write a program that returns a list that contains only the elements that are common between the lists
(without duplicates). Make sure your program works on two lists of different sizes.
Exercise #8
Write a program that asks the user for a string and print out whether this string is a palindrome or not. ( A
palindrome is a string that reads the same forwards and backwards.
Exercise #9
Let’s say I give you a list saved in a variable”
a = [1,4,5,34, 655, 56, 75,3]
Write a one-line Python code that takes this list a and makes a new list that has only the even elemeents of
this list in it.
HANDS – ON EXAM: