100,150,180
The output of the program should be:
18,22,24
Hints:
If the output received is in decimal form, it should be rounded off to its
nearest value (for example, if the output received is 26.0, it should be
printed as 26)
In case of input data being supplied to the question, it should be assumed to
be a console input.
Solution:
#!/usr/bin/env python
import math
c=50
h=30
value = []
items=[x for x in raw_input().split(‘,’)]
for d in items:
value.append(str(int(round(math.sqrt(2*c*float(d)/h)))))
print ‘,’.join(value)
#—————————————-#
#—————————————-#
Question 7
Level 2
Question:
Write a program which takes 2 digits, X,Y as input and generates a 2–
dimensional array. The element value in the i-th row and j-th column of the
array should be i*j.
Note: i=0,1.., X-1; j=0,1,��Y-1.
Example
Suppose the following inputs are given to the program:
3,5
Then, the output of the program should be:
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
Hints:
Note: In case of input data being supplied to the question, it should be
assumed to be a console input in a comma-separated form.
Solution:
input_str = raw_input()
dimensions=[int(x) for x in input_str.split(‘,’)]
rowNum=dimensions[0]
colNum=dimensions[1]
multilist = [[0 for col in range(colNum)] for row in range(rowNum)]
for row in range(rowNum):
for col in range(colNum):
multilist[row][col]= row*col
print multilist
#—————————————-#