Python exercise with solutions (Set 4)
1.To find the smallest and largest number in the given set of numbers.
Input format :
The first line of input contains n numbers separated by space.
Output format :
Print the smallest number and largest number.
Sample input :
4 1 6 8 3 2 9 0
Sample Output :
The smallest number is 0
The largest number is 9
Code :
Output :
2.Sum of array elements with the corresponding elements on reversing the array
Given an array A of n numbers the program should print the sum of the elements of array A with the corresponding elements of the reverse of the array A.
Input format :
The first line should contain the number of elements n in the array.
The second line contain an array of n numbers separated by space.
Output format :
Print the resultant array elements separated by space.
Sample input :
4
3 5 8 1
Sample Output :
4 13 13 4
Explanation :
The array is [3,5,8,1]
The reverse of the array is [1,8,5,3]
The sum of both the above arrays =>[4,13,13,4]
Code :
Output :
3.Multiple of 5
Given a list A of numbers , the program has to print all numbers which are not multiple of 5.
Input format :
The first line of input contain the numbers of a list separated by space
Output format :
Print the numbers in a single line separated by space which are not multiple of 5
Sample input :
4 5 10 2 1 10 5 6
Sample Output :
4 2 1 6
Code :
Output :
4. Digits
You are given a number A which contains only 0's and 1's. Our task is to make all digits same by just flipping one digit (either 0 to 1 or 1 to 0 ) only. If it is possible to make all the digits same by just flipping one digit then print YES else print NO.
Sample input :
101
Sample Output :
YES
Code :
Output :
5.Factorial
For example the factorial of 4 => 1*2*3*4=>24
Sample input :
5
Sample Output :
120
Code :
Output :
Comments
Post a Comment