D522 Python for IT Automation Exam
Question with Verified Correct Answers
Naming Conflict
Occurs when global and local variables share the same name, potentially causing confusion.
Separation of Concerns
Using proper scope to keep program logic organized and maintainable.
Data Type
A classification that specifies the kind of value a variable can store.
Dynamic Typing (Python)
Python determines a variable's type at runtime without explicit declaration.
Integer (`x = 5`)
A numeric data type representing whole numbers.
Float (`y = 3.14`)
A numeric data type representing decimal numbers.
String (`message = "Hello"`)
A sequence of characters enclosed in single or double quotes.
Boolean (`is_true = True`)
A data type that represents either True or False.
List (`my_list = [1, 2, 3]`)
An ordered, mutable sequence of values.
,Tuple (`my_tuple = (1, 2, 3)`)
An ordered, immutable sequence of values.
Range (`my_range = range(5)`)
A sequence type representing a range of numbers.
Dictionary (`my_dict = {'key': 'value'}`)
A mapping type that stores key-value pairs.
Set (`my_set = {1, 2, 3}`)
An unordered collection of unique elements.
NoneType (`my_variable = None`)
Represents the absence of a value.
Type Casting (`int(42)` or `str(42)`)
Explicitly converting a value from one data type to another.
Integer (int) (`x = 5`)
A whole number without a decimal point that can be positive or negative.
Floating-Point (float) (`pi = 3.14`)
A number with a decimal point or scientific notation.
Scientific Notation (`2.0e3`)
A float representation using exponential notation equal to 2000.0.
Mixed-Type Promotion (`5 + 3.14`)
When an int and float are used together, Python automatically converts the result to float.
, Arithmetic with Integers (`x + y`)
Standard math operations applied to whole numbers.
int() Conversion (`int(3.14)`)
Converts a float to an integer by truncating the decimal portion.
float() Conversion (`float(5)`)
Converts an integer into a floating-point number.
round() Function (`round(3.14159, 2)`)
Rounds a number to a specified number of decimal places.
abs() Function (`abs(-5)`)
Returns the absolute (non-negative) value of a number.
Truncation (`int(3.99)`)
Drops the decimal portion instead of rounding when converting to int.
Random Module (`import random`)
Built-in module used to generate random numbers.
Random Range (`random.randrange(1, 101)`)
Generates a random integer within a specified range.
String (`greeting = "hello"`)
A sequence of characters enclosed in single or double quotes.
Multiline String (`"""line1\nline2"""`)
A string that spans multiple lines using triple quotes.
Question with Verified Correct Answers
Naming Conflict
Occurs when global and local variables share the same name, potentially causing confusion.
Separation of Concerns
Using proper scope to keep program logic organized and maintainable.
Data Type
A classification that specifies the kind of value a variable can store.
Dynamic Typing (Python)
Python determines a variable's type at runtime without explicit declaration.
Integer (`x = 5`)
A numeric data type representing whole numbers.
Float (`y = 3.14`)
A numeric data type representing decimal numbers.
String (`message = "Hello"`)
A sequence of characters enclosed in single or double quotes.
Boolean (`is_true = True`)
A data type that represents either True or False.
List (`my_list = [1, 2, 3]`)
An ordered, mutable sequence of values.
,Tuple (`my_tuple = (1, 2, 3)`)
An ordered, immutable sequence of values.
Range (`my_range = range(5)`)
A sequence type representing a range of numbers.
Dictionary (`my_dict = {'key': 'value'}`)
A mapping type that stores key-value pairs.
Set (`my_set = {1, 2, 3}`)
An unordered collection of unique elements.
NoneType (`my_variable = None`)
Represents the absence of a value.
Type Casting (`int(42)` or `str(42)`)
Explicitly converting a value from one data type to another.
Integer (int) (`x = 5`)
A whole number without a decimal point that can be positive or negative.
Floating-Point (float) (`pi = 3.14`)
A number with a decimal point or scientific notation.
Scientific Notation (`2.0e3`)
A float representation using exponential notation equal to 2000.0.
Mixed-Type Promotion (`5 + 3.14`)
When an int and float are used together, Python automatically converts the result to float.
, Arithmetic with Integers (`x + y`)
Standard math operations applied to whole numbers.
int() Conversion (`int(3.14)`)
Converts a float to an integer by truncating the decimal portion.
float() Conversion (`float(5)`)
Converts an integer into a floating-point number.
round() Function (`round(3.14159, 2)`)
Rounds a number to a specified number of decimal places.
abs() Function (`abs(-5)`)
Returns the absolute (non-negative) value of a number.
Truncation (`int(3.99)`)
Drops the decimal portion instead of rounding when converting to int.
Random Module (`import random`)
Built-in module used to generate random numbers.
Random Range (`random.randrange(1, 101)`)
Generates a random integer within a specified range.
String (`greeting = "hello"`)
A sequence of characters enclosed in single or double quotes.
Multiline String (`"""line1\nline2"""`)
A string that spans multiple lines using triple quotes.