Python Assgn
Python Assgn
True
False
1 point
what is the output of the following code snippet?
a = b = c = 300
print(a, b, c)
300
300 300
Error
1 point
Which of the following are valid Python variable names?
4a
1ab
1 point
Which of the following statements assigns the value 10 to the variable x in Python?
x ==10
x=10
x !=10
x :=10
1 point
Which of the following are reserved keywords in Python?
elif
None
class
All of the above
1 point
What is the output of the following?
x=2
for i in range(x):
x += 1
print (x,end="")
34
01
12
23
1 point
What is the output of the following?
for i in range(10):
if i == 5:
break
else:
print(i,end="")
012345
01234
012345678
0123
1 point
What is the output of the following?
for i in range(2.0):
print(i)
0
1
01
Error
1 point
What is the output of the following program?
i=1
while True:
if i:
break
print(i)
i=i+1
2
3
4
5
12345
12
No output is displayed
1 point
What happens when the following code is executed?
n=5
if(n>1):
print(”Hello”)
An error is thrown
1) Input Format:
The first line of the input contains two numbers separated by a space.
Output Format:
Print the addition in single line
Example:
Input:
42
Output:
6
Explanation:
Since the addition of numbers 4 and 2 is 6, hence the output is 6.
1
a,b=input().split(" ")
2
a=int(a)
4
b=int(b)
5
print(a+b,end="")
2) Input Format:
The first line of input contains two numbers separated by a space
Output Format:
Print the smaller number
Example:
Input:
23
Output:
2
1
a,b=input().split(" ")
2
a=int(a)
3
b=int(b)
4
if(a<b):
5
print(a,end="")
6
else:
7
print(b,end="")
3) Given an array A of N numbers (integers), you have to write a program which prints the
sum of the elements of array A with the corresponding elements of the reverse of
array A.
If array A has elements [1,2,3], then reverse of the array A will be [3,2,1] and the
resultant array should be [4,4,4].
Input Format:
The first line of the input contains a number N representing the number of elements in
array A.
The second line of the input contains N numbers separated by a space. (after the last
elements, there is no space)
Output Format:
Print the resultant array elements separated by a space. (no space after the last
element)
Example:
Input:
4
2531
Output:
3883
Explanation:
Here array A is [2,5,3,1] and reverse of this array is [1,3,5,2] and hence the resultant
array is [3,8,8,3]
1
n=int(input())
2
a = [int(i) for i in input().split(' ')]
3
b=[]
4
j=int(len(a))
5
b=a[::-1]
6
c=[]
7
for i in range(j):
8
c.append(a[i]+b[i])
9
print(*c,sep=' ',end="")
Assignment 1
Due date: 2019-08-14, 23:59 IST.
Your last recorded submission was on 2019-08-03, 18:46 IST
1 point
Which of the following is true about a program?
True
False
1 point
Which of the following is a programming language?
BASIC
FROTRAN
LOGO
True
False
1 point
Which of the following can be used to communicate across multiple sprites?
broadcast messages
wait option
sounds options
join operator
1 point
A jumping sprite
A rotating sprite
A stationary sprite
A sleeping sprite
1 point
What kind of block should i use to make my sprite move around?
Sensing
Sound
Motion
Nothing happens
In this assignment, your task is just to read the input number and print it.
Before attempting the programming assignments, please make sure you have gone through
how to attempt the programming assignments.
Input:
The input will contain only one number.
Output:
Output the same number.
Example:
Input:
10
Output:
10
a = int(input()) # this code will take a single input and store it in variable a
NOTE:
You should not display any line like "please enter a number".
Your code should do exactly what has been asked to be done
1
a=int(input())
2
print(a,end="")