Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Mean, Median and Mode

Given a list of integers, write a program to print the mean, median and mode.

Mean - The average value of all the numbers.

Median - The mid point value in the sorted list.

Mode - The most common value in the list. If multiple elements with same frequency are present, print all the values with same frequency.Input


The input will be a single line containing space-separated integers.Output


The first line of output should contain the mean, round off the value to 2 decimal places.

The second line of output should contain the median, round off the value to 2 decimal places.

The third line of output should contain the mode.

See Sample Input/Output for the output format.Explanation


For example, if the given list of integers are

2 4 5 6 7 8 2 4 5 2 3 8

The average of all the numbers is 4.67.


After sorting the array,

2 2 2 3 4 4 5 5 6 7 8 8

Sample Input 1

2 4 5 6 7 8 2 4 5 2 3 8

Sample Output 1

Mean: 4.67

Median: 4.5

Mode: 2









Index of Last Occurrence

Write a program to print the index of the last occurrence of the given number N in the list.Input


The first line of input will contain space-separated integers.

The second line of input will contain an integer N.Output


The output should be the index of the last occurrence of the number N.Explanation


For example, if the given list of numbers and N are

2 4 5 6 7 8 2 4 5 2 3 8
2


Number 2 present at index locations 0, 6, 9, as the last occurrence, is at index 9. So the output should be 9.

Sample Input 1

2 4 5 6 7 8 2 4 5 2 3 8

2

Sample Output 1

9

Sample Input 2

65 87 96 31 32 86 57 69 20 42 32 32

32




Sum of Prime Numbers from M to N

Given two integers M and N, write a program to print the sum of prime numbers from M to N.Input


The first line of input will contain a positive integer (M).

The second line of input will contain a positive integer (N).Output


The output should be a single line containing the sum of prime numbers from M to N.Explanation


For example, if the given M and N are 5 and 11, as all the prime numbers from 5 to 11 are 5, 7, and 11. So the output should be sum of these primes (5+7+11), which is 23.


Similarly, if the given numbers are M is 18 and N is 40, as all the prime numbers from 18 to 40 are 19, 23, 29, 31,and 37. So the output should be sum of these primes (19+23+29+31+37), which is 139.

Sample Input 1

5

11

Sample Output 1

23

Sample Input 2

18

40

Sample Output 2


Shift Numbers - 2

Given a string, write a program to move all the numbers in it to its start.Input


The input will contain a string A.Output


The output should contain a string after moving all the numbers in it to its start.Explanation


For example, if the given string A is "1good23morning456", the output should be "123456goodmorning", as it contains numbers at the start.

Sample Input 1

1good23morning456

Sample Output 1

123456goodmorning

Sample Input 2

com876binat25ion

Sample Output 2

87625combination




Given a string, write a program to return the sum and average of the numbers that appear in the string, ignoring all other characters.


Write a program in python that prompts the user to input the x-y coordinate of a point in a Cartesian plane. The program should then output a message indicating whether the point is the origin, is located on the x- (or y-) axis, or appears in a particular quadrant.

Samples of expected output:

Enter x and y coordinates: 0 0

(0, 0) is the origin


Enter x and y coordinates: 4 0

(4, 0) is on the x-axis


Enter x and y coordinates: 0 -3

(0, -3) is on the y-axis


Enter x and y coordinates: -2 3

(-2, 3) is in the second quadrant


Enter x and y coordinates: 1 -4

(-2, 3) is in the fourth quadrant


Write a program that prompts the user to input the x-y coordinate of a point in a Cartesian plane. The program should then output a message indicating whether the point is the origin, is located on the x- (or y-) axis, or appears in a particular quadrant.

Samples of expected output:

Enter x and y coordinates: 0 0

(0, 0) is the origin


Enter x and y coordinates: 4 0

(4, 0) is on the x-axis


Enter x and y coordinates: 0 -3

(0, -3) is on the y-axis


Enter x and y coordinates: -2 3

(-2, 3) is in the second quadrant


Enter x and y coordinates: 1 -4

(-2, 3) is in the fourth quadrant


Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is


h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday).

q is the day of the month.

m is the month (3: March, 4: April, ..., 12: December). January and February are counted as months 13 and 14 of the previous year.

j is the century (i.e., ⌊year/100⌋).

k is the year of the century (i.e., year % 100).


Write a program that prompts the user to enter a year, month, and day of the month, and then it displays the name of the day of the week. Sample runs of program are given below:



For example, if the given seconds are 200. As 200 seconds is equal to 3 minutes and 20 seconds, and days, hours are zero, so ignore the days and hours. So the output should be "3 Minutes 20 Seconds


Date Format - 2

Given seconds as input, write a program to print in D days H hours M minutes S seconds.Input


The input will be a single line containing an integer.Output


The output should be a single line containing the D Days H Hours M Minutes S Seconds format. Print only the non-zero values.Explanation


For example, if the given seconds are 200. As 200 seconds is equal to 3 minutes and 20 seconds, and days, hours are zero, so ignore the days and hours. So the output should be "3 Minutes 20 Seconds"


output is like if we give as input like 3600 output like 3 min 20sec


and input is like 86400 the output should be like 1 day


LATEST TUTORIALS
APPROVED BY CLIENTS