Which of the following range functions would give the following sequence:
8, 5, 2
range(8,2) |
||
range(2,10,3) |
||
range(8,1,-3) |
||
range(8,3,-2) |
hat is the result of the following expression, assume x = 5?
((x <= 5) and (x!=0))
False |
||
Syntax error |
||
True |
||
5 |
What statement is used to exit out of a loop?
pass |
||
continue |
||
break |
||
exit |
Which of the following is not a Python logical operator?
not |
||
and |
||
or |
||
nor |
SOL:
1) The range functions which give the sequence 8,5,2 is
range(8,1,-3)
so option 3rd is correct
Explanation:
range(8,1,-3) says that it gives the numbers from 8 to 1 with an offset of -3
First it will given 8
next it will give 8-3 = 5
next it will give 5-3 = 2
next 2-3 = -1 so -1 is not in range of 8 to 1 so it will stop there
so range(8,1,-3) is correct
2) TRUE
Explanation:
Given x=5
The expression is ((x<=5) and (x!=0))
The First one is x<=5 --> 5<=5 is TRUE because 5 is equal to 5 here
and next one x!=0 ---> 5!=0 is TRUE because 5 is not equal to 0
so TRUE and TRUE = TRUE
so The answer is TRUE
3) Break is the correct answer
Explanation:
Break statement is used to exit from the Loop
4) nor is not a python logical operator
so option 4 is correct
Explanation:
ALL three operators and,or, not are used as logical operators in python but nor is not used
Get Answers For Free
Most questions answered within 1 hours.