

Python - 5
Presentation
•
Professional Development
•
Professional Development
•
Practice Problem
•
Hard
Mani Ak
Used 1+ times
FREE Resource
5 Slides • 5 Questions
1
Multiple Choice
What will be the output of the following Python code?
Yes, the Value is 6
Result: 1
Yes, the Value is 6
Result: 6
Yes, the Value is 6
Result: None
Result: 1
2
The function funct_exp takes three positional arguments (a, b, c) and variable keyword arguments (**args).
When the function is called, it's given the values 1, 2, and 3 for a, b, and c respectively, and two keyword arguments: action="true" and number="false".
The first if statement checks if args.get("action") == "true", which is true. So it prints "Yes, the Value is 6" (because 1 + 2 + 3 = 6).
The second if statement checks if args.get("number") == "false", which is also true. So it returns the value of a, which is 1.
The returned value (1) is assigned to the variable result.
Finally, "Result: 1" is printed.
3
Multiple Choice
What is the output of the following code?
The code will run successfully and print the values of all parameters.
The code will raise a SyntaxError.
The code will raise a TypeError.
The code will run but only print the values of a and b.
4
Correct answer: B) The code will raise a SyntaxError.
The function definition in this code is incorrect and will raise a SyntaxError.
In Python, the order of parameters in a function definition is important and must follow a specific sequence:
Regular parameters
*args (if used)
Parameters with default values
**kwargs (if used)
In the given function definition, **kwargs comes before args, which violates this order. Additionally, the parameter c with a default value is placed after both *kwargs and *args, which is also incorrect.
5
Multiple Choice
What is the correct code to sort a list of dictionaries data by the values of the 'age' key in ascending order without changing the original list?
sorted_students = sorted(students, key=lambda x: x['name'])
sorted_students = sorted(students, key=lambda x: x['age'])
sorted_students = sorted(students, key=lambda x: x['age'], reverse=True)
sorted_students = sorted(students, key=lambda x: x['name'], reverse=True)
6
Option A is incorrect because This code sorts the list of dictionaries by the name key in ascending order. The lambda function lambda x: x['name'] extracts the value associated with the name key from each dictionary.
Option B is correct, This code sorts the list of dictionaries by the age key in ascending order. The lambda function lambda x: x['age'] extracts the value associated with the age key from each dictionary.
Option C is incorrect, This code sorts the list of dictionaries by the age key in descending order. The lambda function lambda x: x['age'] extracts the value associated with the age key from each dictionary, and the reverse=True parameter specifies that the sorting should be in descending order.
Option D is incorrect, This code sorts the list of dictionaries by the name key in descending order. The lambda function lambda x: x['name'] extracts the value associated with the name key from each dictionary, and the reverse=True parameter specifies that the sorting should be in descending order.
7
Multiple Choice
What will be the output?
True
False
True
True
False
TypeError
True
TypeError
8
First Comparison: {1, 2, 3, 4} == {1, 4, 3, 2}
Explanation: In Python, sets are collections of unique elements that are unordered. The equality operator (==) checks if both sets contain the same elements, regardless of the order.
Result: The sets {1, 2, 3, 4} and {1, 4, 3, 2} contain the same elements. Therefore, the comparison returns True.
Second Comparison: {1, 2, 3, 4} > {1, 2, 3, '4'}
Explanation: The greater than operator (>) is used to check if one set is a proper superset of another set. However, in this case, the sets contain elements of different types (integers and a string). According to Python's comparison rules, comparing objects of different types using == and != is allowed and will generally result in False or True, respectively
9
Multiple Choice
What will be the output?
{3.5, 'g', 6, 3, 'h', 4, 'y'}
{3.5, 'g', 6, 'h', 4, 'y'}
{3.5, 'g', 6, 'h', 'y'}
{3.5, 'g', 6, 3, 'h', 'y'}
10
The symmetric_difference() method removes the common element 3 and combines the remaining elements from both sets.
The resulting set {3.5, 'g', 6, 'h', 4, 'y'} contains all unique elements from both set1 and set2 excluding the common element.
The correct answer is
B)because the symmetric difference ofset1andset2is{3.5, 'g', 6, 'h', 4, 'y'}.
What will be the output of the following Python code?
Yes, the Value is 6
Result: 1
Yes, the Value is 6
Result: 6
Yes, the Value is 6
Result: None
Result: 1
Show answer
Auto Play
Slide 1 / 10
MULTIPLE CHOICE
Similar Resources on Wayground
7 questions
Formative Assessment
Presentation
•
Professional Development
7 questions
Fuel Spill Aviation
Presentation
•
Professional Development
7 questions
Are you smarter than a fifth grader?
Presentation
•
Professional Development
7 questions
Middle School Meeting
Presentation
•
Professional Development
7 questions
Human Resource Management
Presentation
•
Professional Development
8 questions
Words of Affirmation
Presentation
•
Professional Development
8 questions
among us
Presentation
•
KG
7 questions
Google Career Certificates
Presentation
•
Professional Development
Popular Resources on Wayground
24 questions
PBIS-HGMS Day 10
Quiz
•
6th - 8th Grade
10 questions
HCS SCI 03 Summer School Review 3
Quiz
•
3rd Grade
11 questions
Home Scope
Quiz
•
7th - 8th Grade
15 questions
HCS SCI 05 Summer School Assessment 3 Review
Quiz
•
5th Grade
35 questions
Lufkin Road Middle School Student Handbook & Policies Assessment
Quiz
•
7th Grade
18 questions
Geo 11.3 Area of Circles and Sectors
Quiz
•
9th - 11th Grade