0% found this document useful (0 votes)
22 views4 pages

Python AI Quiz: Key Concepts and Answers

The document contains a quiz on Python and AI, divided into multiple sections including multiple choice questions, true/false statements, short answer questions, and media automation application questions. It covers topics such as function syntax, list properties, dictionary characteristics, and media processing functions. An answer key is provided for each section, detailing correct responses and explanations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Python AI Quiz: Key Concepts and Answers

The document contains a quiz on Python and AI, divided into multiple sections including multiple choice questions, true/false statements, short answer questions, and media automation application questions. It covers topics such as function syntax, list properties, dictionary characteristics, and media processing functions. An answer key is provided for each section, detailing correct responses and explanations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python & AI Quiz Dr.

Morhaf
00201149901175
Section A: Multiple Choice Questions (MCQs) [Link] 00201149901175
1. 1. What is the correct syntax to define a function in Python?
a) function myFunc():
b) def myFunc:
c) def myFunc():
d) myFunc() = def
2. 2. Which of the following is not true about Python lists?
a) Lists are immutable
b) Lists can store elements of different data types
c) Lists allow indexing and slicing
d) Lists can be modified after creation
3. 3. What does the media_files.pop() function do?
a) Adds an element
b) Removes the first element
c) Removes and returns the last element
d) Sorts the list
4. 4. In a dictionary, what must all keys be?
a) Mutable
b) Strings
c) Unique
d) Numbers
5. 5. Which method is used to get all values in a dictionary?
a) get()
b) items()
c) keys()
d) values()
6. 6. What output does the function call edit_video("clip1.mp4", "zoom", 5) produce?
a) Editing with zoom effect for 10 seconds
b) Editing clip1.mp4 with zoom effect for 5 seconds
c) clip1.mp4 is zoomed
d) Invalid function call

Section B: True / False [Link] 00201149901175


7. The append() method is used to add an element at a specific index in a list.

8. The return keyword is optional in a Python function.


9. Dictionary values must be unique.

11. Recursion is a technique where a function calls another function.

12. The function clean_title() ensures acronyms stay uppercase and stopwords remain
lowercase.

Section C: Short Answer [Link] 00201149901175


13. Write a function greet_user(name) that returns “Hello, <name>!”.

14. What is the difference between a list and a dictionary in Python?

15. Give one advantage of using functions in programming.

16. What will be the output of this code:


def is_even(x):
return x % 2 == 0
print(is_even(4))

17. How can you safely get a value from a dictionary using a key without causing a
KeyError?

18. In the function def introduce(name, age=30, city="London"), what are the required and
optional parameters?

Section D: Media Automation Application Questions [Link]


00201149901175
19. Briefly describe how the function generate_hashtags() processes input text.

20. What library is used to add a watermark to an image in Python?

21. What does the rename_files() function do in media automation?


Answer Key [Link]
00201149901175
Section A: Multiple Choice Questions [Link] 00201149901175
1. c) def myFunc():

2. a) Lists are immutable

3. c) Removes and returns the last element

4. c) Unique

5. d) values()

6. b) Editing clip1.mp4 with zoom effect for 5 seconds

Section B: True / False


7. False

8. True

9. False

11. False (Recursion is when a function calls itself)

12. True

Section C: Short Answer [Link] 00201149901175


13. def greet_user(name):
return f"Hello, {name}!"

14. A list is an ordered collection of items accessed by index. A dictionary is an unordered


collection of key-value pairs.

15. Reusability – functions allow code to be reused, reducing repetition.

16. True

17. Use the get() method: [Link]('key', default_value)

18. Required: name; Optional: age, city


Section D: Media Automation Application Questions
19. It extracts words, ignores stopwords, converts the rest to lowercase, and adds '#' to
form hashtags.

20. PIL (Pillow) library

21. It renames all files in a directory using a consistent naming pattern with a prefix and
index.

Common questions

Powered by AI

Generating hashtags in media automation involves extracting words from input text, ignoring stopwords, converting remaining words to lowercase, and prefixing them with '#'. This process is significant as it automates the organization and categorization of content for social media platforms, enhancing discoverability and user engagement .

The append() method in Python is designed to add elements to the end of a list, making it unsuitable for inserting elements at specific positions. For such operations, the insert() method is more appropriate as it allows specifying the exact index where the new element should be placed, offering more control over the list's structure .

Contrary to some beliefs, Python lists are not immutable; they can be modified. This feature allows developers to append, remove, or change elements directly, providing flexibility in data management. However, developers need to be cautious about unintended side effects when lists are shared across different parts of an application .

Using unique keys in Python dictionaries significantly enhances data retrieval efficiency by ensuring that each key-value association is distinct, allowing hash table operations to quickly locate the desired value. This results in average-case constant time complexity (O(1)) for lookups, which is critically efficient for large data sets .

The key difference between lists and dictionaries in Python is that lists are ordered collections of items accessed by their index, while dictionaries are unordered collections of key-value pairs. This impacts their usage as lists are ideal for sequential data operations and maintaining data order, whereas dictionaries enable quick lookups via unique keys, making them suitable for scenarios where associations between key-value pairs are needed .

From the function signature def introduce(name, age=30, city="London"), it can be assumed that Python treats parameters without a default value as required, while parameters with default values are optional. This approach allows functions to be flexible in terms of input, supporting various use cases and simplifying function calls without compromising parameter accountability .

The PIL (Pillow) library plays a crucial role in media automation by providing a wide range of image processing capabilities. It allows operations such as adding watermarks, modifying image formats, and performing complex transformations, which are essential in automating workflows that involve managing and customizing media content .

Functions provide significant advantages in programming by allowing code to be reused across different parts of an application, thereby reducing redundancy and improving maintainability. They enable better organization of code, making it easier to read and manage, and allow logic encapsulation, which aids in debugging and testing .

The get() method can be used to safely retrieve a dictionary value without causing a KeyError, as it allows specifying a default value in case the key does not exist. This approach is beneficial as it prevents the program from crashing due to missing keys and provides a graceful way to handle absent data .

Recursion differs from typical function invocation as it involves a function calling itself directly or indirectly, whereas standard function calls invoke different functions or the same function with different control flow. A common use case for recursion is solving problems that can be broken down into smaller, similar sub-problems, like calculating factorials or traversing complex data structures such as trees .

You might also like