Python Test
Python Test
Sec-A
(10 x 1 =10)
1. Does the program below have an error? If so why?
t= ‘hello’
t[0]=”H”
2. What are lists and tuples? What is the key difference between the
two?
3. How is del D and D[<key>] different from one another if D is a
Dictionary?
4. How are dictionaries different from list?
5. What are break, continue and pass in Python?
6. What is the difference between / and // in Python?
7. What is the difference between .py and .pyc files?
8. Consider the code:
string=raw_input(“enter a string”)
count=3
while True:
if string[0]==’a’ :
string[0]=string[2:1]
elif string[-1]==’b’:
string=string[: 2]
else
count+=1
break
print string
print count
[email protected]
Python Test
Sec-B
(6 x 5 =30)
1. WAP to input a range and print all the prime numbers in that range.
2. WAP a menu driven program to input a number and as per user’s
choice check smith number or not, Armstrong number or not.
3. Write a program that reads a date as a positive integer N. The
program prints out the date in the format
December 25 ,2022
[email protected]
Python Test
Sec-C
( 10 x 4 =40)
1. Write a program in Java to accept a string and display the new string
after reversing the characters of each word.
Sample Input:
Computer Science
Sample output:
retupmoC ecneicS
Input:
Enter number of sentences.
1
Enter sentences.
TO BE OR NOT TO BE.
Output:
Total number of words: 6
Word Frequency
OR 1
NOT 1
TO 2
[email protected]
Python Test
BE 2
3. Create a dictionary whose keys are month names and whose values
are the number of days in the corresponding months.
a)Ask the user to enter a month name and use the dictionary
to tell them how many days are in the .month
4. WAP to input any 10 numbers in a list and find the frequency of each
number.
Example:
Input numbers:
4425625 558
Output:
Number Frequency
2 2
4 2
5 3
6 1
8 1