Programming Assignments-1: Addition
In this assignment, you will have to take two numbers (integers) as input and print the addition.
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:
4 2
Output:
6
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:
4 2
Output:
6
Program:
a,b = [int(a) for a in input().split()]
c = a + b
print(c,end='')
Program:
c = a + b
print(c,end='')
Programming Assignment-2: Small
Given two numbers (integers) as input, print the smaller number.
Input Format:
The first line of input contains two numbers separated by a space
Output Format:
Print the smaller number
Example:
Input:
2 3
Output:
2
Program:
if a>b:
print(b,end='')
else:
print(a,end='')
Programming Assignment-3:Loops ,List and Sum
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
2 5 3 1
Output:
3 8 8 3
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
2 5 3 1
Output:
3 8 8 3
Program:
t = [int(a) for a in input().split()]
rev = []
for i in reversed(t):
rev.append(i)
result = []
for i in range(r):
res=t[i]+rev[i]
result.append(res)
print(*result,sep=' ',end='')
0 comments:
Post a Comment