Computer Science
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
Python Tuples
2 Likes
Answer
Statement 4
Reason — The statement that would give an error during execution of the given code is Statement 4 (tup[4] = 80). This is because tuples in Python are immutable, meaning we cannot modify the elements of a tuple after it has been created. Here, it is attempting to assign 80 to the element at the index 4 of a tuple, which results in an error because tuples do not support item assignment.
Answered By
3 Likes
Related Questions
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"]
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
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*
Fill in the blank:
The modem at the sender’s computer end acts as a …………… .
- Model
- Modulator
- Demodulator
- Convertor