0% found this document useful (0 votes)
0 views

important Question CS

The document covers key concepts of dictionaries in Python, including their structure, creation, key importance, value access methods, and deletion techniques. It also introduces Python modules, providing examples and a demonstration of the math module. Additionally, it discusses digital footprints, plagiarism, and the pros and cons of e-waste recycling.

Uploaded by

pvidyarthi8
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)
0 views

important Question CS

The document covers key concepts of dictionaries in Python, including their structure, creation, key importance, value access methods, and deletion techniques. It also introduces Python modules, providing examples and a demonstration of the math module. Additionally, it discusses digital footprints, plagiarism, and the pros and cons of e-waste recycling.

Uploaded by

pvidyarthi8
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/ 5

Chapter: Dictionary

Question 1: What is a dictionary in Python? How is it different from lists?

Answer:
A dictionary in Python is an unordered, mutable collection of key-value pairs.
Each key in a dictionary must be unique, and it is used to access its associated
value.
Difference:

 Dictionary: Stores data as key-value pairs (e.g., {1: "apple", 2:


"banana"}).
 List: Stores data as indexed elements (e.g., ["apple", "banana"]).

Question 2: How can you create an empty dictionary in Python?

Answer:
An empty dictionary can be created using curly braces {} or the dict() function.
Example:-

# Using curly braces

empty_dict1 = {}

# Using the dict() function

empty_dict2 = dict()

Question 3: Explain the importance of keys in a dictionary.

Answer:
Keys in a dictionary are unique identifiers used to store and retrieve values. They
must be immutable types like strings, numbers, or tuples. Keys ensure quick
lookups and data organization.

Question 4: How do you access a value in a dictionary using its key?

Answer:
You can access a value by specifying its key inside square brackets [ ] or using
the get() method.
Example:
my_dict = {"name": "John", "age": 25}
# Using square brackets
print(my_dict["name"]) # Output: John

# Using the get() method


print(my_dict.get("age")) # Output: 25

Question 5: What are the methods to delete an element from a dictionary?

Answer:

 del statement: Removes a specific key-value pair.


 pop() method: Removes and returns the value of the specified key.
 clear() method: Removes all elements from the dictionary.

my_dict = {"name": "John", "age": 25}

# Using del

del my_dict["name"]

# Using pop

age = my_dict.pop("age")

# Using clear

my_dict.clear()

Question 6: Write a Python program to count the frequency of each word in a


given string.
Ans- # Input string
text = "apple banana apple orange banana apple"

# Create an empty dictionary


word_count = {}
# Count frequency
for word in text.split():
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1

# Print the dictionary


print("Word frequencies:", word_count)
Output

Word frequencies: {'apple': 3, 'banana': 2, 'orange': 1}

Chapter: Introduction to Python Modules


Question 1: What are Python modules? Give examples.

Answer:
A Python module is a file containing Python code, such as functions, classes, or
variables, which can be reused in other programs. Modules help organize code and
promote reusability.
Example:

 Built-in module: math, os, random.


 User-defined module: A .py file created by a user.

Question 2: Write a program to demonstrate the use of the math module.

import math

# Using math functions

num = 25

sqrt_value = math.sqrt(num)
factorial_value = math.factorial(5)

# Print results

print("Square root of 25:", sqrt_value)

print("Factorial of 5:", factorial_value)

Output

Square root of 25: 5.0

Factorial of 5: 120

Chapter: Society, Law, and Ethics


Question 1: What is digital footprint? Why is it important?

Answer:
A digital footprint refers to the trail of data left by a person's online activities, such
as browsing history, social media posts, and online purchases.
Importance:

 It helps build online profiles for targeted services.


 It may affect privacy and security.
 It is critical for online reputation management.

Question 2: Explain the term plagiarism. How can it be avoided?

Answer:
Plagiarism is the act of using someone else's work or ideas without proper
acknowledgment, leading to ethical and legal issues.
Avoiding Plagiarism:

1. Cite sources properly.


2. Use quotation marks for direct quotes.
3. Paraphrase content and provide attribution.
4. Use plagiarism detection tools.
Question 3: Write any two advantages and disadvantages of e-waste recycling.

Answer:
Advantages:

1. Reduces pollution by minimizing waste in landfills.


2. Recovers valuable materials like gold and copper.

Disadvantages:

1. Recycling processes can release harmful toxins.


2. It requires high labor and setup costs.

Created with chatgpt


Download id - pvidyarthi

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy