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

Closest Palindrome Number

Given a string N, representing an integer, return the closest integer (not including itself), which is a palindrome. If there is a tie, return the smaller one.

The closest is defined as the absolute difference minimized between two integers.

Input

The input will be a single line containing an integer.

Output

The output should be a single line containing the closest palindrome number to the given integer.

Explanation

For example, if the given integer is 19, the palindrome number greater than 19 is 22 and the palindrome number less than 19 is 11. As 22 is closest to the number 19. So the output should be 22.

For example, if the given integer is 15, the palindrome number greater than 15 is 22 and the palindrome number less than 15 is 11. As 11 is closest to the number 19. So the output should be 11.


Sample Input 1

19


Sample Output 1

22


Sample Input 2

15


Sample Output 2

11




Given a list of integers, write a program to identify the contiguous sub-list that has the largest sum and print the sum. Any non-empty slice of the list with step size 1 can be considered as a contiguous sub-list.Input


The input will contain space-separated integers, denoting the elements of the list.Output


The output should be an integer.Explanation


For example, if the given list is [2, -4, 5, -1, 2, -3], then all the possible contiguous sub-lists will be,

[2]
[2, -4]
[2, -4, 5]
[2, -4, 5, -1]
[2, -4, 5, -1, 2]
[2, -4, 5, -1, 2, -3]
[-4]
[-4, 5]
[-4, 5, -1]
[-4, 5, -1, 2]
[-4, 5, -1, 2, -3]
[5]
[5, -1]
[5, -1, 2]
[5, -1, 2, -3]
[-1]
[-1, 2]
[-1, 2, -3]
[2]
[2, -3]
[-3]

Among the above contiguous sub-lists, the contiguous sub-list [5, -1, 2] has the largest sum which is 6.

Sample Input 1

2 -4 5 -1 2 -3

Sample Output 1

6

Sample Input 2

-2 -3 4 -1 -2 1 5 -3

Sample Output 2

7




Smallest Missing Number

Given a list of numbers, write a program to print the smallest positive integer missing in the given numbers.


Input


The input will be a single line containing numbers separated by space.


Output


The output should be a single line containing the smallest missing number from given numbers.


Explanation


For example, if the input numbers are 3, 1, 2, 5, 3, 7, 7.

The number 1, 2, 3 are present. But the number 4 is not. So 4 is the smallest positive integers that is missing from the given numbers.


Sample Input 1

3 1 2 5 3 7 7


Sample Output 1

4


Sample Input 2

5 5 2 3 1 8 8 4


Sample Output 2

6




Secret Message - 2

Given a string, write a program to print a secret message that replaces characters with numbers 'a' with 1, 'b' with 2, ..., 'z' with 26 where characters are separated by '-'.




a b c d e f g h i j k l m n o p q r s t u v w x y z

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26


Input


Input will be a string in single line containing spaces and letters both uppercase and lowercase.


Output


Output should be a single line containing secret message. All characters in output should be in lower case.


Explanation


For example, if input is "python", "p" should replaced with "16", similarly"y" with "25","t" with "20","h" with "8","o" with "15","n" with "14". So output be "16-25-20-8-15-14".


Sample Input 1

python


Sample Output 1

16-25-20-8-15-14




Sample Input 2

python learning


Sample Output 2

16-25-20-8-15-14 12-5-1-18-14-9-14-7

) Create a program that ask user to input their weight. Imagine that the user was standing on the moon right now, his/her weight would be 16.5 percent of what it is on Earth. If he/she gained a kilo in weight every year for the next 15 years, what would his/her weight be for each year of the 15 years? Write a program using a for loop that prints the user moon weight for each year.


Use a for loop and the list append method to generate the powers of 2 to produce the following result [1, 2, 4, 8, 16, 32, 64, 128]


Write a for loop that prints a dictionary's items in sorted (ascending) order


a. Write a for loop that prints the ASCII code of each character in a string named S. Use the built-in function ord(character) to convert each character to an ASCII integer.

b. Next, change your loop to compute the sum of the ASCII codes of all characters in a string


At the interactive prompt, define a list named L that contains four strings or numbers (e.g., L=[0,1,2,3]). a. What happens when you try to index out of bounds (e.g., L[4])?

b. What about slicing out of bounds (e.g., L[-1000:100])?

c. Finally, how does Python handle it if you try to extract a sequence in reverse—with the lower bound greater than the higher bound (e.g., L[3:1])? Hint: try assigning to this slice(L[3:1]=[‘?’]) and see where the value is put


. Type the expressions below in python interactively, and try to explain what's
happening in each case:
a. 2 ** 16
2 / 5, 2 / 5.0

b. "spam" + "eggs"
S = "ham"
"eggs " + S
S * 5
S[:0]
"green %s and %s" % ("eggs", S)
c. ('x',) [0]
('x', 'y') [1]

d. L = [1,2,3] + [4,5,6]
L, L[:], L[:0], L[-2], L[-2:]
([1,2,3] + [4,5,6]) [2:4]
[L[2], L[3]]
L.reverse(); L
L.sort(); L
L.index(4)
LATEST TUTORIALS
APPROVED BY CLIENTS