Lab 07
Lab 07
Statement Purpose:
The objective of this lab is to make student familiar with programming concepts in Python.
Activity Outcomes:
This lab teaches you the following:
Introduction to Python
Start with basic programming concepts
Lists
Tuples
Dictionaries
Python Variables
Activity 1
# assign a string
fav_lang = "python"
print(fav_lang)
Conditional Statements
Activity 2
# if statement example
if 10 > 5:
print("10 greater than 5")
print("Program ended")
Activity 3
if letter == "B":
print("letter is B")
else:
if letter == "C":
print("letter is C")
else:
if letter == "A":
print("letter is A")
else:
print("letter isn't A, B and C")
Activity 4
if letter == "B":
print("letter is B")
else:
print("letter isn't A, B or C")
Loops
Activity 5
Lists
Activity 6
# Python program to print Even Numbers in a List
# list of numbers
list1 = [10, 21, 4, 45, 66, 93]
# checking condition
if num % 2 == 0:
print(num, end=" ")
Tuple
Activity 7
thistuple = ("apple", "banana", "cherry")
print(thistuple)
# slicing
thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
print(thistuple[2:5])
Sets
Activity 8
Lab Task
1) Create a program that calculates the factorial of a given number using a loop
2) Develop a program that checks whether a given number is a prime number or not.
Use loops and if-else statements to implement the logic.
3) Write a python program that take a list of subjects of your current semester and print
on the console.
4) Write a python program that take a list of food items, perform add, update, and delete
operation on the list.
5) Write a two int type list and perform addition, subtraction and multiplication
operations and print the results.
6) Create different sets for colors, animals, and fruits. Perform different operations like
union, intersection, and difference between sets. Also, perform add, update, and
remove operations on the sets.
7) Create a tuple containing different fruits. Print the content with index no.
8) Create a tuple as above, write the code for combining (“grape,”kiwi”) in the tuple
9) Write a code for to print all items in the above tuple
10) Create an empty dictionary. Add NAME, AGE, AND CITY with values in the
dictionary.
11) Perform different operations on dictionary such as keys(), values() to print the key
and values present in the dictionary
12) Use a for loop to print all the items in the dictionary