Test 3:
Question paper
1. Write a program to display avg of 3 subjects (maths, physics, comp)
(Note: Example program, marks can be any number)
>>> m=56
>>> p=76
>>> c=98
>>> total=m+p+c
>>> avg=total/3
>>> print(avg)
76.66666666666667
>>>
2. Which one is valid in the following print statement:
(1) print(“Rajendra’s Laptop”)
(2.) print('rajendra's laptop')
Ans: (1)
3. Write any example program by using membership operators (‘in’ or “not in”) in python. Hint: Input a=”Mera bharath mahan”
Ans1 : a=”Mera Bharath Mahan”
print(“Mera” in a)
Ans2: a=”Mera Bharath Mahan”
print(“Mera” not in a)
x = 5
y = 10
temp = x
x = y
y = temp
print('The value of x after swapping: {}'.x)
print('The value of y after swapping: {}'.y)
5. Following set of commands are executed in shell, what will be the output?
- >>>a="hello"
- >>>a[:2]
- >>>
b) lo
c) olleh
d) hello
c) olleh
d) hello
View Answer
Answer: a
Explanation: We are printing only the 1st two bytes of string and hence the answer is “he”.
Answer: a
Explanation: We are printing only the 1st two bytes of string and hence the answer is “he”.
6. Write a program to find the word “learning” in the following string data type a
a=” We are learning Python”
7. What is the output when the following statement is executed?
>>>"abcd"[2:]
>>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc
b) ab
c) cd
d) dc
View Answer
Answer: c
Explanation: Slice operation is performed on a string.
8. What is the output when the following code is executed?Answer: c
Explanation: Slice operation is performed on a string.
>>>print (r"\nhello")
View Answer
Answer: \nhello
9. What is the output when following statement is executed ?Answer: \nhello
>>>print('new' 'line')
View Answer
Answer: newline
Answer: newline
10. Which of the following is not a complex number?
a) k = 2 + 3j
b) k = complex(2, 3)
c) k = 2 + 3l
d) k = 2 + 3J
YouTube
related videos
No comments:
Post a Comment