(7). Find the Runner up Score
Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up.
The first line contains n. The second line contains an array.
Example:
5
2 3 6 6 5
Given list is [2,2,6,6,5] the maximun score is 6. second maximum is 5. Hence it would print 5
You have to sort it and take out only unique set. I didn't need to us n input
(6). List Comperhensions
Let's learn about list comprehensions! You are given three integers x, y and z representing the dimensions of a cuboid along with an integer n. Print a list of all possible coordinates given by (i,j,k) on a 3D grid where the sum of i + j + k is not equal to n. Here, (0 <= i <= x); (0 <= j <= y); (0 <= k <= z) . Please use list comprehensions rather than multiple loops, as a learning exercise.
Print an array of the elements that do not sum to n = 3
[[0,0,0],[0,0,1],[0,0,2],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,2]]
Four integers x,y,z and n, each on a separate line.
Constraints. Print the list in lexicographic increasing order.
Example: x=1, y=1, z=2, n=3
Draw a cuboid there going to be total of 12 points.
First find all permutations of [i,j,k] are
[[0,0,0],[0,0,1],[0,0,2],[0,1,0],[0,1,1],[0,1,2],[1,0,0],[1,0,1],[1,0,2],[1,1,0],[1,1,1],[1,1,2]]
Use forloop to list all. Hint
for i in range(x + 1)
for j in range(y + 1)
for k in range(z + 1)
print list of coords
<Given Code>
if __name__ == '__main__':
x = int(input())
y = int(input())
z = int(input())
n = int(input())
<write code here>
(5). Print Function
The included code stub will read an integer, from STDIN.
Without using any string methods, try to print the following:
Example (one line no blank space)
n = 5 would print 12345
n = 3 would print 123
<Given Code>
if __name__ == '__main__':
n = int(input())
try:
<write code here>
except ValueError:
print("Error: input must be between 1 and 150")
(4). Leap Year
An extra day is added to the calendar almost every four years as February 29, and the day is called a leap day. It corrects the calendar for the fact that our planet takes approximately 365.25 days to orbit the sun. A leap year contains a leap day.
In the Gregorian calendar, three conditions are used to identify leap years:
a. The year can be evenly divided by 4, is a leap year, unless:
b. The year can be evenly divided by 100, it is NOT a leap year, unless:
c. The year is also evenly divisible by 400. Then it is a leap year.
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years. Source
Given a year, determine whether it is a leap year. If it is a leap year, return the Boolean True, otherwise return False.
Note that the code stub provided reads from STDIN and passes arguments to the is_leap function. It is only necessary to complete the is_leap function.
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.
Constraints (1900 <= year <= 10**5)
<Given Code>
def is_leap(year):
leap = False
<write your code here>
return leap
year = int(input())
print(is_leap(year))
(3). for loop between Constraints (1 <= n >= 20)
Input 3 prints (0, 1, 4)
Input 5 prints (0, 1, 4, 9, 16)
(2). If-Else
If n is odd, print Weird
If n is even and in the inclusive range of 2 to 5, print 'Not Weird'
If n is even and in the inclusive range of 6 to 20, print Weird
If n is even and greater than 20 , print Not Weird
(1). Arithmetic Operator
The provided code stub reads two integers from STDIN, and Add code to print three lines where:
The first line contains the sum of the two numbers.
The second line contains the difference of the two numbers (first - second).
The third line contains the product of the two numbers.
EX: a=3, b=5 would return (8, -2, 15) (+, -, *)
Constraints (a >= 1 and a <= 10**10) and (b >= 1 and b <= 10**10)