Computer Science
Consider the statements given below and then choose the correct output from the given options:
pride = "#G20 Presidency"
print(pride[-2:2:-2])
- ndsr
- ceieP0
- ceieP
- yndsr
Answer
ceieP0
Reason — The code assigns the string "#G20 Presidency" to the variable pride
. The slicing operation pride[-2:2:-2]
starts from the second last character ("y"), which is at index -2, moves backward by 2 characters at a time due to the step value of -2, and stops before reaching the third character ("G"), which is at index 2. Hence, the output will be 'ceieP0'.
Related Questions
Riya wants to transfer pictures from her mobile phone to her laptop. She uses Bluetooth Technology to connect two devices. Which type of network will be formed in this case?
- PAN
- LAN
- MAN
- WAN
Which of the following will delete key-value pair for key = “Red” from a dictionary D1 ?
- delete D1("Red")
- del D1["Red"]
- del.D1["Red"]
- D1.del["Red"]
Which of the following statement(s) would give an error during execution of the following code ?
tup = (20, 30, 40, 50, 80, 79) print(tup) #Statement 1 print(tup[3] + 50) #Statement 2 print(max(tup)) #Statement 3 tup[4] = 80 #Statement 4
- Statement 1
- Statement 2
- Statement 3
- Statement 4
What possible outputs(s) will be obtained when the following code is executed?
import random myNumber = random.randint(0, 3) COLOR = ["YELLOW", "WHITE", "BLACK", "RED"] for I in range(1, myNumber): print(COLOR[I], end = "*") print()
- RED*
WHITE*
BLACK* - WHITE*
BLACK* - WHITE* WHITE*
BLACK* BLACK* - YELLOW*
WHITE*WHITE*
BLACK* BLACK* BLACK*
- RED*