In mathematics, the notation n! represents the factorial of the nonnegative integer n. The factorial of n is the product of all the nonnegative integers from 1 to n. For example:
7! = 1 x 2 x 3 x 4 x 5 x 6 x 7 = 5,040
Write a program that lets the user enter a nonnegative integer and then uses a loop to calculate the factorial of that number. Print the factorial to standard output.
Sample Run
Enter a nonnegative integer:7↵
5040↵
At one college, the tuition for a full-time student is $8,000 per semester. It has been announced that the tuition will increase by 3 percent each year for the next 5 years. Write a program with a loop that displays the projected semester tuition amount for the next 5 years.
The program should print out the result in the form
In 1 year, the tuition will be $8002.3.
In 2 years, the tuition will be $8103.2.
In 3 years, …
In 4 years, …
In 5 years, …
(If, for example, the tuition would cost 8002.3dollars in one year, etc.)
Sample Run
In 1 year, the tuition will be $8240.0.↵
In 2 years, the tuition will be $8487.2.↵
In 3 years, the tuition will be $8741.816.↵
In 4 years, the tuition will be $9004.07048.↵
In 5 years, the tuition will be $9274.192594400001.↵
use sort() function to sort [34,1,2,6,3,7], [[1,3], [3,2], [1,2], [3,1]] and ['a', 'x', 'e', 'A', 'X', 'E'] and tell us what you observe in 2nd, 3rd list"Number Arrangement
write a program to re-arrange all the numbers appearing in the string in decreasing order.
Note: There will not be any negative numbers or numbers with decimal part.
Input
The input is a string containing the actual sentence.
Output
The output is a string containing the modified sentence as mentioned above.
Explanation
For example, if the actual sentence is It is a 3days 4nights holiday trip.
The numbers in the sentence are 3 and 4.After arranging them in the decreasing order, the output looks like It is a 4days 3nights holiday trip.
Sample Input1
It is a 3days 4nights holiday trip
Sample Output1
It is a 4days 3nights holiday trip
Difficult Addition
Arjun is trying to add two numbers. Since he has learned addition recently, an addition which requires a carry is difficult for him. Your task is to print Easy if the addition does not involve a carry, Otherwise print Hard.
Input
The first line of input contains two space separated integers A and B.
Output
If the addition does not involve a carry,print Easy, otherwise print Hard.
Explanation
When calculating 229 + 390, we have a carry from the tens digit to the hundreds digit, so the answer is Hard.
Sample Input1
123456789 9876543218
Sample Output1
Easy
Sample Input2
229 390
Sample Output2
Hard
Write a program to compute the number of distinct shortest paths between two given vertices in an undirected graph with unit edge lengths. Your algorithm should run in linear time. Input Format: The input is a text file which describes the undirected graph G. The first line of the file specifies n, m, u and v, the number of vertices, the number of edges, and the two given vertices respectively. The next m lines specify the m edges of the graph, one line per edge. An edge is described by its end points (no edge weights are described since all the edges have unit length). If the number of vertices is n, assume that the vertices of the graph are numbered (0,1,..n-1). Output Format: Print the number of distinct shortest paths between vertices u and v. Sample Input (for the graph shown on the right): 6 10 5 0 0 1 0 2 1 2 1 3 1 4 2 3 2 4 3 4 3 5 4 5 Sample Output : 4
Given undirected weighted graph, write a program to find shortest paths from designated source vertex all other vertices graph using Dijkstra’s shortest path algorithm. Input Format: input is text file which describes undirected graph. first line file specifies n, m, s, number vertices, number of edges and source vertex respectively. next m lines specify m edges graph, one line per edge. edge is described by its end points followed by weight of that edge. If number of vertices is n, assume that vertices of graph are numbered (0,1,..n-1). Also assume that edge weights are non-negative. Output Format: Print shortest path from source vertex to each vertices in graph, along with length shortest path. Sample Input ( graph shown on right): 5 8 0 0 1 4 0 2 2 1 2 1 1 3 2 1 4 3 2 3 4 2 4 5 3 4 1 Sample Output : Shortest path to 0: 0 ; cost = 0 Shortest path to 1: 0, 2, 1; cost = 3 Shortest path to 2: 0, 2; cost = 2 Shortest path to 3: 0, 2, 1, 3; cost = 5 Shortest path to 4: 0, 2, 1, 4; cost = 6
Difficult Addition
Arjun is trying to add two numbers. Since he has learned addition recently, an addition which requires a carry is difficult for him. Your task is to print Easy if the addition does not involve a carry, Otherwise print Hard.
Input
The first line of input contains two space separated integers A and B.
Output
If the addition does not involve a carry,print Easy, otherwise print Hard.
Explanation
When calculating 229 + 390, we have a carry from the tens digit to the hundreds digit, so the answer is Hard.
Sample Input1
123456789 9876543218
Sample Output1
Easy
Sample Input2
229 390
Sample Output2
Hard
Lowest and Highest score
The teacher gave out the scores of the science quiz conducted last week and asked the ones with the lowest and highest scores to group up. Print the names of the students with minimum and maximum scores, respectively.
Note: In case of a tie, choose the name which comes first in the (dictionary order).
Sample Input1
2
shakti 24
disha 26
Sample Output1
shakti disha
Sample Input2
3
ajay 23
bijay 24
sanjay 23
Sample Output2
ajay bijay
Your friend sent you a message, however his keyboard is broken and types a # instead of a space.
Replace all of the # characters in the given input with spaces and output the result.