Python Basics || Important Questions || Class 12 || Sumita-Arora || Preeti-Arora || Computer Science


Note :- Click on Question to get Answer


Q. Why is Python interpreted?


Q. Who developed Python?


Q. Is Python a compiler language or an interpreter language?



Q. What is the difference between interactive mode and script mode in Python?


Q. How are keywords different from identifiers?



Q. Differentiate between mutable and immutable objects in Python language with example.


Q. What are literals in Python? How many types of literals are allowed in Python?


Q. How many ways are there in Python to represent an integer literal?


Q. What are data types? What are Python's built-in core data types?


Q. What is a statement ? What is the significance of an empty statement?


Q. If you are asked to label the Python loops as determinable or non-determinable, which label would you give to which loop? Justify your answer.



Q. There are two types of else clauses in Python. What are these two types of else clauses?


Q. What do you understand by the term Iteration?



Q. What is indexing in context to Python strings? Why is it also called two-way indexing?


Q. What is a string slice? How is it useful?


Q. Write a program that reads a string and checks whether it is a palindrome string or not.



Q. How are lists different from strings when both are sequences?


Q. Write the most appropriate list method to perform the following tasks.

(a) Delete a given element from the list.
(b) Delete 3rd element from the list.
(c)Add an element in the end of the list.
(d) Add an element in the beginning of the list.
(e) Add elements of a list in the end of a list.



Q. How are tuples different from lists when both are sequences?


Q. When are dictionaries more useful than lists?



Q. Can sequence operations such as slicing and concatenation be applied to dictionaries? Why?


Q. Why can't Lists be used as keys?


Q. How many types of strings are supported in Python?


Q. What is a tuple?


Q. Differentiate between lists and tuples.



Q. What is a dictionary?


Q. Find errors, underline them and rewrite the same after correcting the following code:-
d1 = dict[]
i = 1
n = input ("Enter number of entries : ")
while i <= n :
    a = input ("Enter name:")
    b = input ("Enter age:")
    d1 (a) = b
    i = i + 1
l = d1.key []
for i in l :
    print (i, '\t', 'd1[ i ]')



Q. Write a program to accept values from a user in a tuple. Add a tuple to it and display its elements one by one. Also display its maximum and minimum value.



Q. Write a Python program to count the number of characters (character frequency) in a string.


Q. Write a program that reads a date as an integers in the format MMDDYYYY. The program will call a function that prints print out the date in the format <month name > <day>, <year>.


Q. Write a program that reads two times in military format and prints the number of hours and minutes between the two times .


Q. Write a Python program to capitalize first and last letters of each word of a given string.



Q. Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.


Q. Write a Python program to print the following floating numbers with no decimal places.


Q. Write a Python program to count and display the vowels of a given text.


Q. Write a Python program to find the second most repeated word in a given string.



Q. Write a Python program to remove duplicates from a list.
a = [10, 20, 30, 20, 10, 50, 60, 40, 80, 50, 40]



Q. Write a Python function that takes two lists and returns True if they have at least one common member.


Q. Write a Python program to sort a dictionary by key.


Q. Write a Python program to create a dictionary from two lists without losing duplicate values.


Q. Which of the following is valid arithmetic operator in Python:
(a) //
(b) ?
(c) <
(d) and



Q. What is an expression and a statement?


Q. Write a program to calculate the mean of a given list of numbers.


Q. Write a program to sort a dictionary’s keys using bubble sort and produce the sorted keys as a list.


Q. Write a program to perform sorting on a given list of strings, on the basis of just the first letter of the strings. Ignore all other letters for sorting purposes. Choose sorting algorithm of yourself.


Q. Write a program that sort a list of tuple – elements in descending order of points using bubble sort. The tuple – element of the list contain following information about different players:
(player number , player name , points )



Q. Write the type of tokens from the following:
(i) if
(ii) roll_no



Q. What is None literal in Python?


Q. The following code is not giving desired output. We want to input value as 20 and obtain output as 40. Could you pinpoint the problem?
Number = input ( "Enter Number")
DoubleTheNumber = Number * 2
Print (DoubleTheNumber)



Q. Why is following code giving errors?
name = "Path Walla"
print("Greetings !!!")
    print("Hello", name)
    print ("How do you do?")



Q. Which data types of Python handle Numbers?


Q. Why is Boolean considered a subtype of integers?


Q. What is the role of comments and indentation in a program?


Q. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
30 = To
for K in range(0, To)
    IF K%4 == 0:
        print (K* 4)
    Else:
        print (K + 3).



Q. Write a program that asks the user to input number of seconds and then expresses it in terms of many minutes and seconds it contains.


Q. Write a program that repeatedly asks from users some numbers until string 'done' is typed. The program should print the sum of all numbers entered.


Q. Write a program to print a square multiplication table as shown below:
1    2    3    4    5    6    7    8    9   
2    4    6    8    10    12    14    16    18   
3    6    9    12    15    18    21    24    27   
4    8    12    16    20    24    28    32    36   
5    10    15    20    25    30    35    40    45   
6    12    18    24    30    36    42    48    54   
7    14    21    28    35    42    49    56    63   
8    16    24    32    40    48    56    64    72   
9    18    27    36    45    54    63    72    81



Q. Figure out the problem with following code fragment. Correct the code and then print the output.
1. s1 = 'must'
2. s2 = 'try'
3. n1 = 10
4. n2 = 3
5. print (s1 + s2)
6. print (s2 * n2)
7. print (s1 + n1)
8. print (s2 * s1)



Q. Find and write the output of the following python code:
x = "abcdef"
i = "a"
while i in x:
    print (i, end = " ")



Q. Consider the following code:
string = input("Enter a string :")
count = 3
while True :
    if string[0] == 'a':
        string = string [2 :]
    elif string[-1] == 'b':
        string = string [: 2]
    else:
        count += 1
        break
print(string)
print(count)
What will be the output produced, if the input is:
(a) aabbcc
(b) aaccbb
(c) abcc



Q. Consider the following code:
Inp = input("Please enter a string : ")
while len(Inp) <= 4:
    if Inp[-1] == 'z':
        Inp = Inp[0: 3] + 'c'
    elif 'a' in Inp :
        Inp = Inp[0] + 'bb'
    elif not int(Inp[0]):
        Inp ='1' + Inp[1:] + 'z'
    else:
        Inp = Inp + '*'
print (Inp)
What will be the output produced if the input is
(i) 1bzz,
(ii)' la'
(iii) abc
(iv)' Oxy',
(v)' xyz'!



Q. Write a program that takes a string with multiple words and then capitalizes the first letter of each word and forms a new string out of it.


Q. What are nested lists?


Q. What does each of the following expressions evaluate to?
Suppose that L is the list
["These", ["are", "a"], ["few", "words"], "that", "we", "will", "use"]
(a) L[3:4] + L[1:2]
(b) "few" in L[2:3]
(c) "few" in L[2]
(d) 4[2][1:]
(e) L[1]+[2]



Q. What is the output produced by the following code snippet?
alst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print (alst[::3])



Q. What will be the output of the following code snippet?
Lst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Lst[::2] = 10, 20, 30, 40, 50, 60
print (Lst)
(a) ValueError: attempt to assign sequence of size 6 to extended slice of size 5
(b) [10, 2, 20, 4, 30, 6, 40, 8, 50, 60]
(c) [1, 2, 10, 20, 30, 40, 50, 60]
(d) [1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]



Q. What will be the output of the following code snippet ?
values = []
for i in range (1,4):
    values.append(i)
    print (values)



Q. What will be the output of the following code ?
rec = {"Name": "Python", "Age":"20"}
r = rec.copy()
print(id(r) == id(rec))
(a) True
(b) False
(c) 0
(d) 1



Q. What will be the output of the following code snippet?
dc1 = {}
dc1[1] = 1
dc1['1']= 2
dc1[1.0] =4
sum = 0
for k in dc1:
    sum += dc1[k]
print (sum)



Q. Predict the output of following code fragment:
fruit = {}
fl = ['Apple', 'Banana', 'apple', 'Banana']
for index in fl:
    if index in fruit:
        fruit[index] += 1
    else:
        fruit[index] = 1
    print (fruit)
print (len(fruit))



Q. Find the error in following code. State the reason of the error.
alst ={ 'a':1, 'b':2, 'c':3}
print (alst['a', 'b']).



Q. Find the error in the following code fragment. State the reason behind the error.
box = {}
jars = {}
crates = {}
box['biscuit'] = 1
box['cake' ] = 3
jars['jam'] = 4
crates['box'] = box
crates['jars'] = jars
print (crates [box])



Q. Write the most appropriate list method to perform the following tasks.
(a) Delete a given element from the list.
(b) Delete 3rd element from the list.
(c) Add an element in the end of the list.
(d) Add an element in the beginning of the list.
(e) Add elements of a list in the end of a list.



Q. How can you say that a tuple is an ordered list of objects?


Q. Following code is trying to create a tuple with a single item. But when we try to obtain the length of the tuple is, Python gives error. Why? What is the solution ?
>>> t = (6)
>>> len(t)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    len(t)
TypeError: object of type 'int' has no len()
>>>




Q. What is the length of the tuple shown below ?
t = (((('a', 1), 'b', 'c'), 'd, 2), 'e', 3)



Q. Can tuples be nested?


Q. How are dictionaries different from lists?


Q. How are objects stored in lists and dictionaries different?


Q. If the addition of a new key:value pair causes the size of the dictionary to grow beyond its original size, an error occurs. True or false?

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post