0% found this document useful (0 votes)
23 views2 pages

Python Programming Questions and Answers

The document consists of a series of questions related to Python programming, covering topics such as syntax for control structures, output of specific code snippets, and identifying data types. It includes tasks like writing programs, explaining functions, and predicting outputs of given code. The questions are divided into two parts, with each part requiring answers to 12 questions.

Uploaded by

abilash3277
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Python Programming Questions and Answers

The document consists of a series of questions related to Python programming, covering topics such as syntax for control structures, output of specific code snippets, and identifying data types. It includes tasks like writing programs, explaining functions, and predicting outputs of given code. The questions are divided into two parts, with each part requiring answers to 12 questions.

Uploaded by

abilash3277
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PART-V ANSWER ANY 12 QUESTIONS ONLY 12X2=24

1. Write is the syntax of if.. else statement


2. What is the output of the following python code?
for x in range(5,20,5):
print (x, end=’ ‘)
3. What is the output of following python code?
for x in (10, 20, 30):
print (“Hello World”)

4. What will be the output of the given python?


str= “COMPUTER SCIENCE”
a) print(str*2) b) print (str[0:7] )

5. What is the output of the following python code?


str1=’WELCOME’
a) print ([Link]()) b) print ([Link]())

6. What is the output of the following python code?


str1=”welcome”
a) print ([Link]()) b) print ([Link]())

7. What will be the value of x in following python code?


List1=[2,4,6[1,3,5] ]
x=len(List1)

8. What will be output of the python code?


Squares = [x**2 for x in range (1,11)]
print (Squares) (M-2023)

9. What will be output of the following snippet?


Mydict={chr(x):x for x in range(97,102)}
Print(Mydict)

10. What will be output of the following snippet?


set_A={'A', 2, 4, 'D'}
set_B={'A', 'B', 'C', 'D'}
print(set_A & set_B)

11. Write a query that selects all students whose age is less than 18 in order wise.
12. Write the syntax of [Link] method

13. Identify Which of the following are constructors and selectors?


(a) N1:=number( ) (b) accetnum(n1)

14. Identify Which of the following are constructors and selectors?


(a) displaynum(n1) (b) eval(a/b) (c) x,y:= makeslope (m), makeslope(n)

15. Identify Which of the following are List, Tuple and class?
(a) x:= [2, 5, 6.5, [5, 6], 8.2] (b) employee [eno, ename, esal, eaddress]

16. Identify Which of the following are List, Tuple and class?
(a) arr [1, 2, 34] (b) arr (1, 2, 34) (b) student [rno, name, mark]
PART-V ANSWER ANY 12 QUESTIONS ONLY 12X3=36
1. Identify Which of the following are List, Tuple and class?
(a) employee [eno, ename, esal, eaddress] (b) arr [1, 2, 34] (c) arr (1, 2, 34)
2. Write a program to display.
A *****
AB ****
AB C [OR] ***
AB C D **
AB C D E *
3. Using if.. else.. elif statement write a suitable program to display largest of 3 numbers.
4. Write the syntax of while loop.
5. Write the syntax of Nested if elif .else statement with example.
6. Draw a flow chart to explain while loop
7. Write a Python code to check whether a given year is leap year or not.
8. Write a Python program to display the given pattern.
COMPUTER C
COMPUTE CO
C O M P U T [OR] COM
COMPU COMP
COMP COMPU
COM COMPUT
CO COMPUTE
C COMPUTER
9. Write a short about the followings with suitable example.
(a)capitalize() (b) swap case()
10. What will be the output of the given python program?
str1 = "welcome"
str2 = "to school"
str3=str1[:2]+str2[len(str2)-2:]
print(str3)
11. What will be the output of the given Python program?
a = "Computer"
b = "Science"
x = a[:4] +b[len(b)-3:]
print(x)
12. What will be the output of the given python program? str1=”THOLKAPPIYAM”
[Link](str1[4:]) [Link](str1[4::2]) [Link](str1[::3]) [Link](str1[::-3])
13. What will be output of the following python program?
str1 = "welcome"
str2 = "to school"
str3 = str1[:3]+str2[len(str2)-1:]
print(str3)
14. What will be the output of the following code?
list = [2**x for x in range(5)]
print(list)
15. What will be the output of the following code?
list = [3**x for x in range(5)]
print(list)
16. What will be the output of the following python code?
squares=[ ] for x in range (1,6):
s=x**2 squares. append(s)
print (squares)

17. Identify) the module, operator, definition name for the following: Welcome . display()

Common questions

Powered by AI

The program 'for x in (10, 20, 30): print("Hello World")' prints "Hello World" three times, once for each element in the tuple (10, 20, 30). The loop iterates through each element, executing the print statement each time .

The output of the snippet 'set_A={'A', 2, 4, 'D'}; set_B={'A', 'B', 'C', 'D'}; print(set_A & set_B)' is {'A', 'D'}. The expression 'set_A & set_B' computes the intersection of the two sets, which includes only the elements present in both sets .

The syntax of the if..else statement in Python is: ```python if condition: statement(s) else: statement(s) ``` The 'if' statement evaluates a condition (an expression that returns True or False). If the condition is True, it executes the block of code under the 'if'. If the condition is False, the code under the 'else' is executed. This allows for conditional branching in Python programs .

Python's list comprehension '[x**2 for x in range(1,11)]' generates a list by iterating through numbers in the range from 1 to 10, squaring each number, and collecting the results in a list. The output will be the list: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100].

The slicing operation 'str1[::-3]' with 'str1' initialized as "welcome" reverses the string and selects every third character starting from the end. The output will be 'eoe'. This is because it starts from the last character and moves backwards in steps of three .

In Python, the colon within square brackets is used for slicing strings. 'str1[:2]' takes the first two characters of 'str1'. 'str2[len(str2)-2:]' extracts the last two characters of 'str2'. Concatenating these slices results in a new string composed of these selected segments .

The 'capitalize()' method in Python returns a copy of a string with the first character converted to uppercase and all other characters converted to lowercase. For example, using '"hello world".capitalize()' will return 'Hello world'. This method helps standardize strings to a title-case format .

The code 'for x in range(1, 6): print('C' * x)' iteratively prints strings composed of the character 'C', increasing in length with each iteration. The final output would be: C CC CCC CCCC CCCCC Each line adds one more 'C' than the previous line, resulting in an incremental pyramid pattern of 'C's .

The list comprehension '[2**x for x in range(5)]' produces the output [1, 2, 4, 8, 16]. This is because it iterates over the range 0 to 4, and for each 'x', it calculates 2 raised to the power of 'x', collecting these powers of two in a list .

The expression 'str1="WELCOME"; print(str1.islower())' calls the 'islower()' method on the string 'str1'. This method returns True if all alphabetic characters in the string are lowercase and there is at least one alphabetic character. Since "WELCOME" is entirely uppercase, 'str1.islower()' evaluates to False, so the output is 'False' .

You might also like