Computer Science
Predict the output of the following code fragments:
x = 'one'
y = 'two'
counter = 0
while counter < len(x):
print(x[counter], y[counter])
counter += 1
Python
Python Funda
14 Likes
Answer
o t
n w
e o
Working
Inside the while loop, each letter of x and y is accessed one by one and printed.
Answered By
3 Likes
Related Questions
Predict the output of the following code fragments:
x = [1,2,3] counter = 0 while counter < len(x): print(x[counter] * '%') for y in x: print(y * '* ') counter += 1
Predict the output of the following code fragments:
for x in 'lamp': print(str.upper(x))
Predict the output of the following code fragments:
x = "apple, pear, peach" y = x.split(", ") for z in y : print(z)
Predict the output of the following code fragments:
x ='apple, pear, peach, grapefruit' y = x.split(', ') for z in y: if z < 'm': print(str.lower(z)) else: print(str.upper(z))