KEMBAR78
Session 7 - Data Types | PDF
0% found this document useful (0 votes)
7 views7 pages

Session 7 - Data Types

Embedded Data Types

Uploaded by

Lara Sobh
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)
7 views7 pages

Session 7 - Data Types

Embedded Data Types

Uploaded by

Lara Sobh
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
You are on page 1/ 7

Data Types

1. Basic Inventory Check

A store has a list of products and their stock levels. Write a program that:

• Asks the user for a product name.

• Checks if the product is in stock.

• If available, print "Product is in stock!" Otherwise, print "Product not found!"

2. Storing Student Grades


Write a program that:

• Stores student names and their grades as tuples inside a list.

• Prints all student names and their grades.


3. Simple Matrix Addition

Write a program that:

• Creates two 2×2 matrices (lists of lists).

• Adds the corresponding elements and prints the new matrix.

4. Unique Product Names (Sets)

Write a program that:

• Stores a list of product names.

• Converts them into a set to remove duplicates.

• Prints the unique product names.


5. Customer Purchases Dictionary
Write a program that:

• Stores customer names as keys and their purchases as values in a dictionary.

• Prints each customer’s purchases.

6. Word Frequency Counter

Write a program that takes a sentence as input and counts the frequency of each word.
Ignore case differences.

Example Input:

Enter a sentence: Python is great and Python is fun

Example Output:

Word Frequencies:

python: 2

is: 2

great: 1

and: 1

fun: 1
7. Set Operations: Student Course Enrollment

Problem:

Create two sets:

• One contains students enrolled in Math.

• The other contains students enrolled in Science.

Perform the following:

1. Find students enrolled in both courses.

2. Find students enrolled in either course but not both.

3. Find students only in Math, not in Science.


Input:

math_students = {"Alice", "Bob", "Charlie"}

science_students = {"Bob", "David", "Charlie"}

output:

Both: {'Bob', 'Charlie'}

Either but not both: {'Alice', 'David'}

Only in Math: {'Alice'}


8. Dictionary-Based Inventory System
Problem:

Write a program that manages a store inventory using a dictionary.

• The dictionary keys are item names (strings).

• The values are stock quantities (integers).

The program should allow users to:

• Add new items


• Update stock for existing items
• Remove items from inventory
• View all available stock

Hint: Use a loop and a dictionary with input validation.

You might also like