0% found this document useful (0 votes)
5 views3 pages

Python Basics Lab for Data Science

The lab sheet outlines a 2-hour session for the Foundations of Data Science course focused on basic Python programming. Students will learn about variables, data types, input/output, conditional statements, loops, and functions through hands-on tasks and mini challenges. The session includes environment setup, practical exercises, and a checklist for lab submission.

Uploaded by

f20220042
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Python Basics Lab for Data Science

The lab sheet outlines a 2-hour session for the Foundations of Data Science course focused on basic Python programming. Students will learn about variables, data types, input/output, conditional statements, loops, and functions through hands-on tasks and mini challenges. The session includes environment setup, practical exercises, and a checklist for lab submission.

Uploaded by

f20220042
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lab Sheet: Python Basics

Course: Foundations of Data Science (CS F320)

Duration: 2 hours

Session Objective:
By the end of this lab, students will be able to write and run basic Python programs
involving variables, data types, input/output, conditional statements, loops, and simple
functions.

Environment Setup (15 mins)


1. Open Jupyter Notebook (recommended) or Google Collab or any Python IDE (e.g., VS
Code).
2. Confirm Python 3.x is installed (python --version).
3. Create a new notebook or .py file titled: python_basics_lab.py

Section 1: Variables and Data Types (15 mins)


Task 1: Create variables of different types:

# Integer
age = 20

# Float
temperature = 36.6

# String
name = "Ananya"

# Boolean
is_student = True

Try it yourself:
- Print the type of each variable using type().
- Change the value of a variable and observe the change in type (if any).

Section 2: Input and Output (10 mins)


Task 2: Use input() and print() to interact with the user:

name = input("Enter your name: ")


print("Hello,", name)
Try it yourself:
- Ask the user for their age, then print a message: "You will be X years old next year."

Section 3: Conditional Statements (15 mins)


Task 3: Write a simple program to check if a number is positive, negative, or zero.

num = int(input("Enter a number: "))


if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")

Try it yourself:
- Write a program that checks whether a number is even or odd.

Section 4: Loops (20 mins)


Task 4: Print numbers from 1 to 10 using a for loop and a while loop:

# For loop
for i in range(1, 11):
print(i)

# While loop
i=1
while i <= 10:
print(i)
i += 1

Try it yourself:
- Write a loop to print the first 10 even numbers.
- Write a loop to print the multiplication table of a given number (e.g., 5).

Section 5: Functions (20 mins)


Task 5: Define and call a simple function:

def greet(name):
print("Hello,", name)

greet("Ananya")
Try it yourself:
- Create a function to calculate the square of a number.
- Create a function to check if a number is prime.

Section 6: Mini Challenges (20 mins)


1. Simple Calculator
- Ask user for two numbers and an operator (+, -, *, /)
- Perform the operation using conditionals

2. Sum of Digits
- Input a number (e.g., 1234) and compute the sum of its digits.

3. Fibonacci Series (first N terms)


- Input: n = 7 → Output: 0 1 1 2 3 5 8

Lab Submission Checklist


- [ ] Completed all Try-it-yourself tasks
- [ ] At least one mini challenge attempted
- [ ] Code is properly commented
- [ ] Submitted notebook or .py file

Additional Resources (For Self-Study)


- [Link]
- [Link]
- [Link]

You might also like