What is the purpose of the function 'add_cubes'?
Click to see answer
To calculate and add the surface area of two cubes.
Click to see question
What is the purpose of the function 'add_cubes'?
To calculate and add the surface area of two cubes.
What is the purpose of the provided program?
To check if a 3-digit number is an Armstrong number.
What is the result of math.pow(6.5, 2)?
42.25
What is the output of the Student_info function when called with name='Raju', rollno=111, group='MSDs'?
{'name': 'Raju', 'rollno': 111, 'group': 'MSDs'}
What does the method str1.isupper() check for?
Returns True if the string is non-empty and has all uppercase alphabets or at least one uppercase character with the rest being non-alphabet characters.
What are the two membership operators in Python?
'in' and 'not in'.
What does math.sqrt(x) compute?
The square root of x.
What operations can be performed on string data types in Python?
Concatenation, repetition, membership, and slicing.
What does the len(sys.argv) function return?
The number of command line arguments passed to the program.
What symbol is used for the repetition operator in Python?
The symbol *.
What does the join() method do?
It returns a string in which the characters in the string have been joined by a separator.
What is the output of random.randint(3, 7)?
4
What is the effect of the lower() method?
It converts all uppercase letters in the string to lowercase.
What is an example of an Armstrong number?
153, since 111 + 555 + 333 = 153.
Can negative indexes be used in string slicing?
Yes, negative indexes can be used for slicing.
What does the function math.floor(x) return?
The floor value of x.
What does the 'in' operator do in Python?
It returns True if the first string appears as a substring in the second string, otherwise False.
What is the output format of the calcFact() function?
It prints 'Factorial of [num] is [fact]'.
What is the sine of 0 in radians using math.sin?
0
What does the random module do?
Generates random numbers.
Provide an example of traversing a string using a while loop.
str1 = 'Hello World!'; index = 0; while index < len(str1): print(str1[index]); index += 1.
What is the value of the local variable 'num' in the function 'myfunc'?
What is a void function in Python?
A function that does not have a return statement and returns None.
How do you import the math module in Python?
Using the statement 'import math'.
What does str1.replace('o', '*') do?
Replaces all occurrences of 'o' with '*'.
What does it mean that a string is immutable in Python?
It means that the contents of the string cannot be changed after it has been created.
What does the method str1.islower() return?
False if the string contains any uppercase letters or is empty.
What does the method str1.count('Hello') return?
3, indicating the number of occurrences of 'Hello' in the string.
What does the find() method return if the substring is not present?
-1.
What does the nested function 'cube_surfacearea' calculate?
The surface area of a cube given its side length.
What does the len() method return?
It returns the length of the given string.
What will be printed when accessing 'num1' outside of 'myfunc'?
'Accessing num outside myfunc' will print 5.
What is the general syntax for calling a function in Python?
function_name(parameter_1, parameter_2,...)
How do you import the statistics module?
Using the statement: import statistics.
What is the output of math.gcd(10, 2)?
2
How does the calcFact() function calculate the factorial?
By multiplying 'fact' by each integer from 'num' down to 1 in a loop.
What does the 'sumSquares' function calculate?
The sum of the first n natural numbers.
What does the join() string method do?
It returns a string by joining all the elements of an iterable, separated by a string separator.
What will str1.isupper() return for the string 'HELLO 1234'?
True.
What is the purpose of the for loop in the command line arguments example?
To print each command line argument.
What is the default starting index if the first index is not mentioned in slicing?
The slice starts from index 0.
What is the output of the print statements in the provided code?
Raju is 23 years old (three times).
What does the statistics module provide?
Functions for calculating statistics of numeric data.
What does the upper() method do?
It converts all lowercase letters in the string to uppercase.
What is the purpose of the math module in Python?
It contains different types of mathematical functions.
What is the initial value of the variable 'fact' in the calcFact() function?
What is a global variable?
A variable defined outside any function or block, accessible in any function defined afterwards.
What is the purpose of slicing in Python?
To access some part of a string or substring.
What is the input for the 'sumSquares' function?
An integer value for n, provided by the user.
What happens when the first index is greater than the second index in string slicing?
It results in an empty string.
What is the output of str1.replace('Hello','Bye') when str1 is 'Hello World! Hello'?
'Bye World! Bye'
What does random.random() return?
A random real number (float) in the range 0.0 to 1.0.
What is the purpose of **kwargs in a Python function?
It allows passing a variable length of keyword arguments.
What advantage do keyword arguments provide?
They allow us to ignore the order of arguments.
What is the default step size in string slicing?
The default step size is one.
What is the output of math.ceil(-9.7)?
-9
What will str1.islower() return for str1 = 'hello world!'?
True.
What is the purpose of the user-defined function calcFact()?
To calculate and display the factorial of a number passed as an argument.
What does the input function do in the provided code?
It prompts the user to enter a number, which is then converted to an integer.
What is the output of math.sqrt(144)?
12.0
How do you concatenate two strings in Python?
By using the concatenation operator +.
What is the general syntax for defining a function in Python?
def function_name(list_of_parameters): statement_1 statement_2 ...
What is the purpose of the find(str, start, end) method?
It returns the index of the first occurrence of the substring str within the specified range.
How do you denote *args in a function definition?
By using an asterisk (*) before the parameter name.
What does str1.lstrip() do?
Removes spaces only on the left side of the string.
What defines an Armstrong number?
The sum of cubes of each digit is equal to the number itself.
Provide an example of a function without arguments in Python.
def display(): print('Function without arguments') display()
What does the function Student_info do with **kwargs?
It prints the keyword arguments passed to it.
How is the index of the last character in a string represented using negative indexing?
-n, where n is the length of the string.
What keyword is used to define a function in Python?
def
What does the replace() method do in Python?
It replaces occurrences of a specified substring with another substring.
How do you import the random module?
Using the statement: import random.
What is the formula used in 'cube_surfacearea' to calculate surface area?
6 * pow(x, 2).
What does the title() method do?
It returns the string with the first letter of every word in uppercase and the rest in lowercase.
What does the 'return' statement do in a function?
It returns values from the function to the caller.
What does the partition() method do?
It partitions the string at the first occurrence of a substring and returns three parts: before the separator, the separator, and after the separator.
What happens in a function without parameters and without return value?
There is no data transfer; execution control jumps to the called function and returns to the calling function.
What is the output of 'addition(10, 20, 30)'?
The sum is 60.
What default values are used in the 'addition' function?
num2 = 9 and num3 = 5.
What is the output of the 'add' function when inputs are 10 and 20?
What does importing a module allow you to do?
Access all the functions in the module.
What is the purpose of the user-defined function 'addnum'?
To add two numbers and display their sum.
What does the 'not in' operator do in Python?
It returns True if the first string does not appear as a substring in the second string, otherwise False.
How does Python handle command line arguments?
It stores them in a list using the sys module, accessible via sys.argv.
How long does a local variable exist?
It exists only until the function executes.
What is the formula to find the area of a trapezium?
Area = (1/2) * (a + b) * h, where a and b are the bases and h is the height.
Does the original string change after using the repetition operator?
No, the original string remains the same.
What does every function in Python return by default?
None value.
What does the index() method do differently than find()?
It raises an exception if the substring is not found.
How do you denote **kwargs in a function definition?
By using a double asterisk (**) before the parameter name.
How does the Python interpreter match keyword arguments to parameters?
By using the keyword provided to match with the respective parameter.
What is the output of the 'add' function when called with 2 and 2?
What does the capitalize() method do?
It returns a copy of the string with its first character capitalized and the rest lowercased.
What method is used to convert a string to uppercase in Python?
str1.upper()
What is the output of statistics.mode([11,24,11,45,11])?
11
What inputs does the 'addnum' function require?
Two integers from the user.
What happens when a global variable is changed?
Any change will impact all functions in the program where that variable can be accessed.
How do you perform slicing on a string in Python?
By specifying an index range using the string variable name followed by square brackets.
What components are specified in slicing to access a substring?
Starting index, ending index, and step.
What does *args allow in a Python function?
It allows passing a variable number of non-keyword arguments.
What does the method str1.istitle() check?
Returns True if the string is non-empty and in title case, meaning the first letter of every word is uppercase and the rest are lowercase.
What are keyword arguments in Python?
Arguments passed as a value along with the parameter name (kwarg = value).
What does the syntax str1[n:m:k] represent in string slicing?
It means every kth character is extracted from str1 starting from n and ending at m - 1.
What does the function math.ceil(x) return?
The ceiling value of x.
What does the method isalnum() check for?
It returns True if the string contains only alphabets or numeric characters.
What is the output when 'addition(10, 20)' is called?
The sum is 39.
What is a global variable?
A variable that has global scope.
How can you get a list of modules available in Python?
By using the statement help('module').
What method removes leading whitespace from a string?
str1.lstrip()
What is a module in Python?
A grouping of functions, created as a Python (.py) file containing function definitions.
How do you use a module in Python?
By importing the module using the import statement.
What does a negative index in Python allow you to do?
Access characters of a string from right to left.
What happens if you try to change the contents of an immutable string in Python?
It would lead to an error.
What is a local variable?
A variable defined inside a function or block, accessible only within that function or block.
What are the two special symbols used in Python to pass a variable number of arguments to a function?
*args and **kwargs.
In the provided program, what is the value of the global variable 'num1'?
What does the function 'area_trapezium' calculate?
It calculates the area of a trapezium using the provided bases and height.
How would you join the string 'HelloWorld!' with a separator ' - '?
'H - e - l - l - o - W - o - r - l - d - !'
What are default parameters in Python?
Parameters that have a default value assigned in the function definition.
What does str1.strip() accomplish?
Removes spaces from both the left and right sides of the string.
What is the purpose of the function 'student_info'?
To print the roll number, student name, and group of a student.
What is the output when the input is 121?
121 is not an Armstrong number.
What does the function statistics.median(x) return?
The median (middle value) of x.
What is the output when 'addition(10)' is called?
The sum is 24.
How can you check if a string is alphanumeric?
Using str1.isalnum()
How can strings be created in Python?
By enclosing characters in single, double, or triple quotes.
Can the index in Python be an expression?
Yes, it can include variables and operators but must evaluate to an integer.
What is the index of the first character from the right in a string?
-1.
How does the 'sumSquares' function compute the sum?
By iterating through a range from 1 to n and accumulating the sum.
How can you traverse a string using a for loop?
By iterating through each character in the string using a for loop.
What is the output of the 'sumSquares' function?
The sum of the first n natural numbers.
How should parameters be separated in a function definition?
With a comma.
What will str1.find('Hello', 10, 20) return if str1 = 'Hello World! Hello Hello'?
What is the output of the 'main' function when 'add_cubes(2, 3)' is called?
The surface area after adding two cubes is 66.
What is the purpose of str1.rstrip()?
Removes spaces only on the right side of the string.
What will the function 'add' return when called with arguments 2 and 2?
It will return 4.
What is the output of str1.partition('is') when str1 is 'India is a Great Country'?
('India ', 'is', ' a Great Country')
In a function with parameters and without return value, what type of data transfer occurs?
Data transfer occurs from the calling function to the called function (parameters), but not back (no return value).
What is the output of math.floor(4.5)?
4
How can you convert a string to lowercase in Python?
Using str1.lower()
Which method is used to capitalize the first letter of each word in a string?
str1.title()
What is a string in Python?
A sequence of characters enclosed in quotes.
What is indexing in the context of strings?
A technique to access individual characters in a string using their position.
What does the method str1.isspace() return?
True if the string is non-empty and all characters are white spaces.
What should you save the command line arguments example code as?
Filename.py (e.g., Command.py).
What happens if the second index is not mentioned in string slicing?
The slicing is done till the length of the string.
What is required to execute a function's code in Python?
A function call.
What does str1.endswith('World!') return if str1 = 'Hello World!'?
True.
What happens if a function with default parameters is called without providing all arguments?
It executes with the provided values for the arguments and uses default values for any missing arguments.
What does the function statistics.mean(x) return?
The arithmetic mean of x.
How is the 'student_info' function called with keyword arguments?
student_info(name = 'Raju', rollNo = 111, group = 'MSDs').
What does the case_conversion function do?
It converts uppercase letters to lowercase and vice versa in a given string.
What is the output of statistics.mode(('red','blue','red'))?
'red'
What is the output of math.pow(3, 2)?
9.0
What are the four classifications of functions based on data flow?
What does the example function 'largest' do?
It returns the maximum value from the passed numbers.
What does the count() method return?
It returns the number of times a substring occurs in the given string within specified start and end indices.
What is the output of statistics.mean([11,24,32,45,51])?
32.6
What is the output of math.fabs(-6.7)?
6.7
What does the function math.gcd(x, y) return?
The greatest common divisor of x and y.
How do you remove trailing whitespace from a string?
Using str1.rstrip()
What is the output of the function 'largest' when called with (20, 35)?
What does startswith() return?
True if the string starts with the supplied substring, otherwise False.
What is the difference between lower() and casefold() methods?
casefold() converts more characters into lower case compared to lower().
What does the function statistics.mode(x) return?
The mode (the most repeated value) of x.
How can you check if all characters in a string are uppercase?
Using str1.isupper()
What does it mean to give a step size of -1 in string slicing?
It returns the string in reverse order.
What is the output when the input is 407?
407 is an Armstrong number.
What is the output of statistics.median([11,24,32,45,51])?
32
What is the output of math.factorial(5)?
120
What is the purpose of the from statement in Python?
To access only the required functions from a module.
What is the purpose of curly braces {} in f-strings?
They act as placeholders for values to be evaluated.
What type of values can be used as an index in Python strings?
The index must be an integer (positive, zero, or negative).
What will str1.replace('World', 'Country') return for the string 'Hello World!'?
'Hello Country!'.
What method capitalizes the first letter of a string?
str1.capitalize()
What method checks if all characters in a string are lowercase?
str1.islower()
Are single quotes and double quotes treated the same in Python?
Yes, both are treated the same.
What is the purpose of the 'add' function in the example provided?
To take two inputs, add them, and print the result.
What does the function math.fabs(x) return?
The absolute value of x.
What does the function math.factorial(x) return?
The factorial of x.
How can you view the content of a specific module like math?
By typing help('math').
How can you remove both leading and trailing whitespace from a string?
Using str1.strip()
What is the output of str.capitalize() when str is 'hello world!'?
'Hello world!'
What is the scope of a variable?
The part of the program where a variable is accessible.
What is a local variable?
A variable that has local scope.
What does the function math.pow(x, y) calculate?
x raised to the power of y.
What is an f-string in Python?
A string formatting method introduced in Python 3.6 that uses an f prefix and {} brackets.
What does the swapcase() method do?
It swaps the case of all characters in the string.
What is the index of the first character in a string?
What is the advantage of using f-strings for string formatting?
They are faster, more readable, concise, and less error-prone.
How do you create a string variable in Python?
By assigning a string value to a variable, e.g., str1 = 'Hello World!'
What happens if an index value is out of range?
An IndexError is raised.
What is a function in Python?
A block of statements under a name that can execute independently.
What are the main purposes of using functions?
To perform specific tasks, divide larger problems into smaller parts, implement code reusability, and improve code readability.
What are built-in functions in Python?
Functions and methods that are provided by Python and are always available.
What are user-defined functions in Python?
Functions and methods created by the user.
What is the syntax for importing a module?
import modulename1 [,modulename2, …]
How do you call a function from a module?
By using the syntax modulename.functionname().