Advertisements
Advertisements
Question
Select the correct output of the code:
a = "Year 2022 at All the best"
a = a.split('2')
b = a[0] + ". " + a[1] + ". " + a[3]
print (b)
Options
Year . 0. at All the best
Year 0. at All the best
Year . 022. at All the best
Year . 0. at all the best
Solution
Year . 0. at All the best
APPEARS IN
RELATED QUESTIONS
Consider the given expression:
not True and False or True
Which of the following will be the correct output if the given expression is evaluated?
Assertion (A): To use a function from a particular module, we need to import the module.
Reason (R): Import statement can be written anywhere in the program, before using a function from that module.
Given is a Python list declaration:
Listofnames = ["Aman", "Ankit", "Ashish", "Rajan", "Rajat"]
Write the output of:
print (Listofnames [−1:−4:−1])
Consider the following tuple declaration:
tup1 = ( 10, 20, 30, (10, 20, 30), 40)
Write the output of:
print(tupl.index(20))
What possible output(s) are expected to be displayed on the screen at the time of execution of the following program:
import random
M=[5, 10, 15, 20, 25, 30]
for i in range(1, 3):
first=random.randint(2, 5)-1
sec=random.randint(3, 6)-2
third=random.randint(1, 4)
print(M[first],M[sec],M[third],sep="#")
Predict the output of the code given below:
def makenew(mystr):
newstr.=.""
count=0
for i in mystr:
if count%2 ! = 0:
newstr=newstr+str(count)
else:
if i.lower():
newstr = newstr + i.upper ()
else:
newstr = newstr + i
count+=1
Print(newstr)
makenew("No@1")
Shreyas is a programmer, who has recently been given a task to write a user-defined function named write_bin ()
to create a binary file called Cust_file.dat
containing customer information – customer number (c_no)
, name (c_name)
, quantity (qty)
, price (price)
and amount (amt)
of each customer.
The function accepts customer number, name, quantity and price. Thereafter, it displays the message 'Quantity less than 10.....Cannot SAVE', if the quantity entered is less than 10. Otherwise, the function calculates the amount as price*quantity
and then writes the record in the form of a list into the binary file.
import pickle
def write_bin ():
bin_file = ____________ # Statement 1
while True:
c_no = int (input (“enter customer name”))
c_name = input (“enter customer name”)
qty = int (input ("enter qty"))
price = int (input ("enter price”))
if ________ # Statement2
print (“Quantity less than 10.. Cannot SAVE")
else:
amt = price * gty
c_detail = [c_no, c_name, qty, price, amt]
__________ # Statement 3
ans = input (" Do you wish to enter more records y/n”) if ans. lower () == 'n’:
__________ # Statement 4
____________ # Statement 5
____________#Statement 6
(i) Write the correct statement to open a file 'Cust_file.dat’
for writing the data of the customer.
(ii) Which statement should Shreyas fill in statement 2 to check whether the quantity is less than 10?
(iii) Which statement should Shreyas fill in Statement 3 to write data to the binary file and in Statement 4 to stop further processing if the user does not wish to enter more records?
OR
(iii) What should Shreyas fill in Statement 5 to close the binary file named Cust_file.dat
and in Statement 6 to call a function to write data in the binary file?
What possible outputs(s) will be obtained when the following code is executed?
import random
myNumber=random.randint (0, 3)
COLOR=["YELLOW", "WHITE", "BLACK", "RED"]
for I in range (1, myNumber) :
print (COLOR [I], end="*")
print ()
- Assertion(A): Python standard library consists of number of modules.
- Reasoning(R): A function in a module is used to simplify the code and avoids repetition.
Write a function countNow (PLACES) in Python, that takes the dictionary, PLACES as an argument and displays the names (in uppercase) of the places whose names are longer than 5 characters.
For example, Consider the following dictionary
PLACES={1:"Delhi",2:"London",3:"Paris",4:"New York",5:"Doha"}
The output should be:
- LONDON
- NEW YORK
Write the Python statement for the following task using the BUILT-IN function/method only:
To insert an element 200 at the third position, in the list L1.
Write the Python statement for the following task using the BUILT-IN function/method only:
To check whether a string named, message ends with a full stop/period or not.
Select the correct output of the code:
s = "Python is fun"
l = s.split()
s_new = "_".join([1[0].upper(), 1[1], 1[2].capitalize()])
print(s_new)
A list named studentAge stores age of students of a class. Write the Python command to import the required module and (using built-in function) to display the most common age value from the given list.