Lab 01 Manual - Intro To Python
Lab 01 Manual - Intro To Python
Saqib Nazir
Semester: Group:
Fundamentals of Programming II
Introduction
This laboratory exercise will introduce the fundamental aspects of the Python
programming language which is a very popular language and used extensively in
the area of Machine Learning.
Objectives
Lab Conduct
Fundamentals of Programming II
Theory
Python is an open-source, interpreted language which is widely used for machine
learning tasks in research, academia and industry. It has an easy-to-learn syntax
and is ideal for writing programs in a short duration. The python interpreter can
be downloaded from the website and installed on the system. By default, the
IDLE program is installed. For machine learning, it is recommended to switch to
a more powerful IDE such as PyCharm, Spyder and Jupyter etc. For this lab, we
will use Google Colab for writing python code. Google Colab is a cloud-based
platform that allows you to write python code in your web browser and provides
free access to computing resources such as GPUs.
Fundamentals of Programming II
Lab Task 1 _________________________________________________________________________ [2]
Write a program which evaluates the following three expressions for when x =
1,2,3,4 and 5.
(b) Provide the code for both expressions in the indicated regions:
Fundamentals of Programming II
Lab Task 2 _________________________________________________________________________ [1]
Write a program that reads in two integer inputs, then determines and prints if
the first is a multiple of the second. To input a variable, use the following syntax:
variable = input(“prompt_message”)
Remember that the above function returns a string which is stored in the
variable. You need to explicitly convert the string variable to an integer type
using the int() casting. Provide the code and screenshot of the result.
if condition:
statement_1
else:
statement_2
Fundamentals of Programming II
### TASK 3 CODE STARTS HERE ###
Fundamentals of Programming II
Lab Task 5 _________________________________________________________________________ [1]
Write a program that calculates the factorial of a number. To calculate the
factorial, you will need to make use of a while loop. The syntax of the while loop
is given as follows:
while condition:
statement_1
statement_2
def function_name:
statement_1
statement_2
…
return output
Fundamentals of Programming II
### TASK 6 CODE STARTS HERE ###
Fundamentals of Programming II
Lab Task 8 _________________________________________________________________________ [1]
Write a program that generates the following number sequences and print the
output. You can use the range() function for this task. Use a loop to invoke the
range function iteratively.
1, 2, 3… 20
2, 4, 6… 40
3, 6, 9… 60
4, 8, 12 … 80
…
10, 20, 30… 200
Fundamentals of Programming II