stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
PYTHON PROWESS Flashcards | StudBud
Explore
/
PYTHON PROWESS
PYTHON PROWESS
20 terms
·
StudBud Administration
Imported from external platform
Flashcards
20 cards
F
Practice quiz
P
Host live
L
Questions
20
Answers
1
What is the purpose of string slicing in Python?
To split a string into a list
To convert strings to numbers
To remove characters from a string
To extract a substring from a string
2
What is the output of the following loop?for i in range(3): print(i)
3 2 1 0
1 2 3
0 1 2
0 1 2 3
3
How do you read the content of a text file in Python?
readlines()
read()
readline()
load()
4
complete the code
if n == 0: return 1
all of these
return n * factorial(n - 1)
return 1
5
What is the process of using a function defined in another file in your current Python program?
Function integration
Function inclusion
Function importing
Function attachment
6
Which of the following methods is used to find the index of a substring in a string?
index()
locate()
find()
search()
7
What does the
in
operator do when used with strings?
Concatenates two strings
Converts the string to uppercase
Checks if a string is empty
Checks if a character exists in the string
8
How can you exit a loop prematurely before its normal completion?
Using the return statement
Using the exit() function
Using the continue statement
Using the break statement
9
How are parameters passed to a function in Python?
By defining the parameters in square brackets []
By directly writing the parameters inside parentheses ()
By using the pass keyword
By passing them as arguments when calling the function
10
complete the code
fib_sequence = [0, 1]
for i in range(2, n):
all these
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
11
What is the correct way to write data to a file in Python?
open(file, 'w')
write(data, file)
write(data)
append(data)
12
What is the purpose of the
open()
function in Python?
To open a database connection
To open a web page in the browser
To open a new window in the GUI
To open a file for reading
13
What is the purpose of a variable in Python?
To perform mathematical operations
To create loops
To define functions
To store and manipulate data
14
code to read the content of a text file named "data.txt" and determine if a specific word exists in the file.
found=True
none
with open("data.txt", 'r') as file
if word_to_find in file.read(): found = True
15
What are the different data types in Python?
int, char, double, array, dict
char, double, bool, list, map
numbers, strings, booleans, arrays
int, str, float, bool, list, tuple, dict, set
16
Write a Python program to find the largest number among three given numbers
if a > b: largest_number = a
max(a, b, c)
none
if a > b and a > c: largest_number = a
17
How do you get input from the user in Python?
user_input
input()
get_input()
read()
18
What does the
return
statement do in a function?
It checks the validity of the function
It stops the function from executing further.
It prints the output of the function.
It returns a value from the function.
19
complete the code program to count the number of occurrences of a specific word in a given sentence.
none
if word == "the": word_count += 1
word_count = sentence.count(word)
word_count = len(sentence.split())
20
What is the purpose of the
while
statement in Python?
To iterate over a sequence of elements
To execute a block of code repeatedly while a condition is true
To create an infinite loop
To define a user-defined function