What is the value of y after the following code is executed

Assignment Help Python Programming
Reference no: EM132356347

Answer the Following Questions:

1. Which of the code snippets will print the string Python in reverse order?

1 s = "Python" r=reversed(s)
print("The string in reverse form is ", r)
2 s = "Python"
r=reversed(s)
print("The string in reverse
form is ", "".join(r))
3 s = "Python" r=reversed(s) for i in r:
print(i, end='')
4 Only 1 and 2
5 Only 2 and 3

2. What is the output of the following code?

stationery = ("book", "pen", "pencil")
for i in range(len(stationery)):
print(stationery[-i] ,
end=" ")

1 book pencil pen
2 book pen pencil
3 pencil pen book
4 None of these

3. What is the output of the following code?
word ="xyz"
for i in range(len(word)): print(word[-i], end=" ")

1 x z y
2 x y z
3 z y x
4 None of these

4. What is the output of the following code?
taste
=["sweet","sour","bitter"] print("s" in taste)

1 False
2 True
3 sweet sour
4 None of these

5. Which of the following statements will create and initialise an array a with values 0, 2, 4, 6, 8

1 a=[0 for i in range(5)]
2 a=[i for i in range(5)]
3 a=[2*i for i in range(5)]
4 None of these

6. What is the output of the following code?
arr=[i * i for i in range(5)] print(arr)

1 [0, 1, 4, 9, 16]
2 [0, 0, 0, 0, 0]
3 [0, 1, 2, 3, 4]
4 None of these

7. If arr is declared as an array and initialised, which of the code snippets will output [0, 1, 4, 9, 16] ?

1 arr=[i*i for i in range(5)]
print(arr)
2 arr=[i for i in range(5)] for x in range(5):
arr[x]*=x
print(arr)
3 arr=[0 for i in range(5)] for x in range(len(arr)):
arr[x]+=x*x
print(arr)
4 All the above

8. If arr is an array which of the code snippets will output 1 2 3 4 5 from the array?

1 arr=[i for i in range(5,0,-1)] for x in range(len(arr), 0, - 1):
print(arr[x-1], end=" ")
2 arr=[i for i in range(1,6)] for j in range(5):
print(arr[j], end=" ")
3 arr=[i for i in range(5)] for j in range(5):
print(arr[j], end=" ")
4 Only 2 and 3
5 Only 1 & 2

9. What is the value of y after the following code is executed?
arr=[x for x in (12, 36, 1,9)]
y=0
for x in range(len(arr)): if arr[x] > y:
y = arr[x]

1 0
2 1
3 9
4 12
5 36

10. Array arr is initialised with elements 1, 2, 3, and 4. Which of the code snippets will double each element of the array arr?

1 arr=[x for x in (1, 2, 3, 4)] for x in range(len(arr)):
arr[x]+=arr[x]
2 arr=[x for x in (1, 2, 3, 4)] for x in range(len(arr)):
arr[x]+=x+1
3 Both 1 & 2
4 Only 1

11. Which is the statement that declares and initialises(with zero) a two dimensional array variable m with 3 rows and 4 columns?

1 m=[[0 for i in j in range(4)] range(3)] for
2 m=[4*[0] for i in range(3)]
3 m=[[0 for i in j in range(3)] range(4)] for
4 Both 1 and 2
5 Both 2 and 3

12. Which of the code snippets will output a 3 X 4 matrix(two dimensional array with 3 rows and 4 columns) as below:

1 m=[[i for i in range(4)] for j in range(3)]
for row in m:
for e in row:
print(e, end=" ") print()
0 1 2 3
0 1 2 3
0 1 2 3
2 m=[4*[i] for i in range(3)] for row in m:
for e in row:
print(e, end=" ") print()
3 Both 1 and 2
4 None of these

13. m is a matrix with the following elements: 0 1 2 3 1 for i in range(3):
for j in range(4): print(2 *m[i][j],
end=" ")
print()
0 1 2 3
0 1 2 3

Which code snippet will double each element so that m is altered and printed as: 2 for i in range(3):
for j in range(4): m[i][j]+=m[i][j]
print(m[i][j], end="
")
print()
0 2 4 6
0 2 4 6
0 2 4 6
3 for i in range(3):
for j in range(4): m[i][j]*=m[i][j]
print(m[i][j], end="
")
print()
4 None of these

14. m is a matrix with the following elements:

2 4 6 8
2 4 6 8
2 4 6 8

What is the output of the following code:
for i in range(3): s=0
for j in range(4): s+=m[i][j]
print(s, end=" ")

1 2 4 6 8
2 20 20 20
3 60
4 None of these

15. m is a matrix with the following elements:

2 4 6 8
2 4 6 8
2 4 6 8
What is the output of the following code:
for i in range(4): s=0
for j in range(3): s+=m[j][i]
print(s, end=" ")

1 2 4 6 8
2 20 20 20
3 60
4 None of these

16. Array variable x is initialised as follows:

x=[[i*j for j in range(3)] for i in range(2)]
What will the print(x) statement output?

1 [[0, 0, 0], [0, 1, 2]]
2 [[0, 0, 0], [0, 0, 0]]
3 [[0, 1, 2], [0, 1, 2]]
4 None of these

17. Array variable x is initialised as follows:
x=[[i*j for j in range(3)] for i in range(2)]
Which is the element at the position
x[1][2]?

1 0
2 1
3 2
4 3
5 None of these

18. m is a matrix with the following elements:

0 1 2 3
0 1 2 3
0 1 2 3 1 for i in range(3):
for j in range(4): m[i][j]+=m[i][j]
print(m[i][j], end="
")
print()
Which code snippet will double each element so that m is altered and printed as:
2 for i in range(3):
for j in range(4): m[i][j]*=m[i][j]
print(m[i][j], end="
")
print()
0 2 4 6
0 2 4 6
0 2 4 6
3 for i in range(len(m)): for j in range(len(m[i])):
print(m[i][j],end=" ")
print()
4 Both 1 & 2
5 Both 1 & 3

19. An example of an immutable sequence in Python is ...

1 Lists
2 Strings
3 Integers
4 None of these

20. a=(‘dog', ‘cat', ‘fish').
Here, a is an example
of a ... variable.

1 String
2 Block
3 List
4 Tuple

Reference no: EM132356347

Questions Cloud

Discuss the freedom of speech as topic in cyber law : Freedom of speech- The essay will discuss the freedom of speech as a topic in cyber law.
Describe the proportion of phone apps which are free : BUS708 Statistics and Data Analysis Assignment - Using Dataset 1, describe the proportion of phone apps which are free
Create a program that asks the user to enter a string : Create a program that asks the user to enter a string that is temporarily stored in variable x. The program should use a method to know if the entered value.
Implementing cybersecurity in the energy sector : ITS 834-Implementing Cybersecurity in Energy Sector. You have been hired as security consultant for EnergyA which is electric utility company based in USA.
What is the value of y after the following code is executed : Which is the statement that declares and initialises with zero a two dimensional array variable m with 3 rows and 4 columns?
Challenges of international competition and expansion : BUMGT5920 - Management in a Global Business Environment - Describe, using academic references, the international challenges and possible opportunities
Detect emerging threats and strengthen countermeasures : How defense-in-depth (chapter 6) and awareness (chapter 10) are complimentary techniques to detect emerging threats and strengthen countermeasures
Calculate and prints the area of a rectangle : Create a Python program that calculates and prints the area of a rectangle. The length of the rectangle is 6 and the breadth is 4. No input is required.
Which function is used to receive input from users : In computation if operands of different types are involved, Python converts the operand with "smaller" type to the "larger" type. What is this called?

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd