Matrix Diagonal Sum
Given a square matrix, print the sum all diagonal elements of the matrix.
Input
The first line of input will be an integer N, denoting the no. of rows in the matrix. The following N lines will contain space-separated integers denoting the elements of each row of the matrix.
Output
The output should be a single integer denoting the sum of all the diagonal elements.
Explanation
For example, if the given N is 3, and the given matrix is
1 2 3
4 5 6
7 8 9
The diagonal and anti-diagonal elements of the above matrix are 1, 3, 5, 7, 9. So the output should be 25
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample Output
25
Repeating & Non-Repeating Numbers
Given a list of numbers, find and print, the first number that occurs only once in the list and the first number that occurs more than once in the list.
Input
The input will be a single line containing space-separated integers.
Output
The first line of the output should contain the first non-repeating number. The second line of output should contain first repeating number. If there is no number fitting the given criteria, print "None" instead.
Explanation
For example, if the given list of integers are 5, 5, 4, 7, 4, 1, 11 , the first non-repeating number is 7 and the first repeating number is 5.
Sample Input 1
5 5 4 7 4 1 11
Sample Output 1
7
5
Sample Input 2
1 2 3 4 5 6 7 8 9
Sample Output 2
1
None
You are given the temperature T of an object in one of Celsius, Fahrenheit, and Kelvin scales.
Write a program to print T in all scales viz Celsius, Fahrenheit, and Kelvin.
Formula to convert from Fahrenheit F to Celsius C is C = (F - 32) * 5 / 9.
Formula to convert from Kelvin K to Celsius C is C = K - 273.
Here "C", "F", "K" represent that the temperature scale is in Celsius, Fahrenheit and Kelvin scales respectively. The input contains the temperature (a number) and the unit of the temperature scale (C, F, K) without any space. The output contains temperature in Celsius, Fahrenheit and Kelvin scales in each line in the format similar to input and the value of the temperature is rounded to 2 decimal places.
You are writing a line of code that should ask the user to input the balance of their bank account in dollars and cents. The program will then perform a multiplication problem to tell the user how much interest they can earn. Identify three errors in your line of input code and explain why they are incorrect. Include the corrected line of code in your answer. Here is the code:
1num = input(What is your balance?)
Ordered Matrix
Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.
Input
The first line of input will contain two space-separated integers, denoting the M and N.
The next M following lines will contain N space-separated integers, denoting the elements of each list.
Output
The output should be M lines containing the ordered matrix.
Note: There is a space at the end of each line.
Explanation
For example, if the given M is 3 and N is 3, read the inputs in the next three lines if the numbers given in the next three lines are the following.
1 20 3
30 10 2
5 11 15By ordering all the elements of the matrix in increasing order, the ordered matrix should be
1 2 3
5 10 11
15 20 30Sample Input 1
3 3
1 20 3
30 10 2
5 11 15
Sample Output 1
1 2 3
5 10 11
15 20 30
Sample Input 2
2 5
-50 20 3 25 -20
88 17 38 72 -10
Sample Output 2
-50 -20 -10 3 17
20 25 38 72 88
Write a python code to read a dataset (may be CSV file) and print all features i.e. columns of the dataset. Determine the descriptive statistics i.e. Maximum, Minimum Mean Median, Count, Variance, Standard Deviation etc. of the numeric features like age, salary etc., may be present in the dataset.
Write Program to perform following tasks (10 Marks)
a. Create a database SELECTION_DB
b. Set connection with mysql.connector.connect.
c. Create a table EMP_SELECTION in database SELECTION_DB with following data FIRST_NAME,LAST_NAME,AGE,GENDER,INCOME.
d. change table structure / (add, edit, remove column of a table) at run time
i. add a column address in the EMP_SELECTIONtable.
ii. execute SQL INSERT statement to create a record into EMP_SELECTION table
iii. run the query to updates all the records having GENDER as 'M', and increase AGE of all the males by one year.
iv. delete all the records from EMP_SELECTION Table where AGE is less than 18 .
Numbers in String - 2
Given a string, write a program to return the sum and average of the numbers that appear in the string, ignoring all other characters.
Input
The input will be a single line containing a string.
Output
The output should contain the sum and average of the numbers that appear in the string.
Note: Round the average value to two decimal places.
Explanation
For example, if the given string is "I am 25 years and 10 months old", the numbers are 25, 10. Your code should print the sum of the numbers(35) and the average of the numbers(17.5) in the new line.
Sample Input 1
I am 25 years and 10 months old
Sample Output 1
35
17.5
Sample Input 2
Tech Foundation 35567
Sample Output 2
35567
35567.0
Add two polynomials
Given two polynomials A and B, write a program that adds the given two polynomials A and B
Output
Print the addition of polynomials A and B.
If the degree of polynomial is zero and the constant term is also zero, then just print 0 to represent the polynomial.
For term Cix^Pi, if the coefficient of the term Ci is 1, simply print x^Pi instead of 1x^Pi.Explanation
Sample Input 1:-
6
0 -20
1 23
2 30
3 19
4 6
5 17
9
0 -100
5 -89
6 -20
7 -1
1 20
2 4
3 99
4 -45
8 12
Sample Output 1:-
12x^8 - x^7 - 20x^6 - 72x^5 - 39x^4 + 118x^3 + 34x^2 + 43x - 120
Note :- Need Space between - and + operators
Sample Input 2:-
4
0 5
1 0
2 10
3 6
3
0 1
1 2
2 4
Sample Output 2:-
6x^3 + 14x^2 + 2x + 6
Note:- Need Space between - and + operators
Sample Input 3:-
5
0 -2
3 6
4 7
1 -3
2 -1
5
0 1
1 2
2 -4
3 3
4 5
Sample Output 3:-
12x^4 + 9x^3 - 5x^2 - x - 1
Note:- Need Space between - and + operators
Area of Largest Rectangle in Histogram
Given an list of integer
The input will be a single line containing space-separated integers, denoting the heights of the bars.
The output should be a single line containing the area of the largest rectangle in the rectangle.
For example, if the given list of numbers are
2 1 5 6 2 3 , when they are drawn adjacent to each other according to their heights, the histogram will be like The largest rectangle can be found in between 5 and 6, which is 10.
Sample Input 1
2 1 5 6 2 3
Sample Output 1
10
Sample Input 2
65 87 96 31 32 86 57 69 20 42
Sample Output 2
248