0% found this document useful (0 votes)
64 views

Python Assgn

This document outlines an assignment for an online programming course. It includes multiple choice questions to test programming concepts and sample code problems to solve. The last section provides instructions for an introductory assignment to get comfortable with the online programming environment by reading an input number and printing it out.

Uploaded by

Kavitha Pammi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Python Assgn

This document outlines an assignment for an online programming course. It includes multiple choice questions to test programming concepts and sample code problems to solve. The last section provides instructions for an introductory assignment to get comfortable with the online programming environment by reading an input number and printing it out.

Uploaded by

Kavitha Pammi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment 2

Due date: 2019-08-14, 23:59 IST.


Your last recorded submission was on 2019-08-05, 11:23 IST
1 point
State True or False.
In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type.

True

False

1 point
what is the output of the following code snippet?
a = b = c = 300
print(a, b, c)

300

300 300 300

300 300

Error

1 point
Which of the following are valid Python variable names?

4a

1ab

All of the above

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

0 0.1 0.2 ..... till 2

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”)

Hello gets printed

Nothing gets printed

An error is thrown

None of the above

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?

A program is a set of instructions

A program performs a specific task

A program is an executable file

All of the above


1 point
State True or False.
A program can be written in simple english language

True

False
1 point
Which of the following is a programming language?

BASIC

FROTRAN

LOGO

All of the above


1 point
State True or False.
Programming languages are used to give instructions to computers.

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

Which of the following is an output of the above set of instructions?

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

None of the above


1 point
Which of the following is a facility provided by Scratch to use sound effects?

A sound library is provided

We can record sound using a microphone

We can use a sound file

All the above


1 point
What happens when the green flag symbol is clicked in Scratch?

The program starts


The program gets deleted

The program halts

Nothing happens

Assignment: Introduction to Online Portal


Due on 2019-08-14, 23:59 IST
This assignment is just to make you people comfortable with the NPTEL programming
environment.

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

How to take input in python:

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="")

You might also like