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
output:
35
17.5
sample Input 2
Lear4 python7
output:
11
5.5
sample Input 3
Anjali25 is python4 Expert
output:
29
14.5
Acronyms
You are given some abbreviations as input. Write a program to print the acronyms separated by a dot(
.) of those abbreviations.
Input
The first line of input contains space-separated strings.
Explanation
Consider the given abbreviation,
Indian Administrative Service. We need to consider the first character in each of the words to get the acronym. We get the letter I from the first string Indian, we get the letter A from the second word Administrative, and we get the letter S from the third word Service. So, the final output should be I.A.S.
Sample Input 1
Indian Administrative Service
Sample Output 1
I.A.S
Sample Input 2
Very Important Person
Sample Output 2
V.I.P
Replacing Characters of Sentence
You are given a string
S. Write a program to replace each letter of the string with the next letter that comes in the English alphabet.
Note: Ensure that while replacing the letters, uppercase should be replaced with uppercase letters, and lowercase should be replaced with lowercase letters.
Input
The first line of input is a string.
Explanation
In the given example,
Hello World.
If we replace each letter with the letter that comes next in the English alphabet,
H becomes I, e becomes f and so on ... So, the output should be Ifmmp Xpsme.
Sample Input 1
Hello World
Sample Output 1
Ifmmp Xpsme
Sample Input 2
Something is better than Nothing
Sample Output 2
Tpnfuijoh jt cfuufs uibo Opuijoh
Roots of a quadratic equation
You are given cofficients
a, b and c of a quadratic equation ax2 + bx + c = 0. Find the roots r1, r2 of the equation.
Note:
r1 and r2 should be rounded upto 2 decimal places.
Input
The first line of input is an integer
a. The second line of input is an integer b. The third line of input is an integer c.
Explanation
In the given example, a = 1, b = -5, c = 6. Then the equation is x2 - 5x + 6 = 0
r1 = (-b + (b^2 - 4*a*c)^0.5)/2*a
r1 = (5 + (25 - 24))/2
r1 = 3
and
r2 = (-b - (b^2 - 4*a*c)^0.5)/2*a
r2 = (5 - (25 - 24))/2
r2 = 2
So, the output should be
3
2
Sample Input 1
1
-5
6
Sample Output 1
3.0
2.0
Sample Input 2
-1
1
6
Sample Output 2
-2.0
3.0
Diamond
Given an integer value
N, write a program to print a number diamond of 2*N -1 rows as shown below.
Input
The first line of input is an integer
N.
Explanation
In the given example, the number of rows in the diamond is
5.
So, the output should be
. . . . 0 . . . .
. . . 0 0 0 . . .
. . 0 0 0 0 0 . .
. 0 0 0 0 0 0 0 .
0 0 0 0 0 0 0 0 0
. 0 0 0 0 0 0 0 .
. . 0 0 0 0 0 . .
. . . 0 0 0 . . .
. . . . 0 . . . .
Sample Input 1
5
Sample Output 1
. . . . 0 . . . .
. . . 0 0 0 . . .
. . 0 0 0 0 0 . .
. 0 0 0 0 0 0 0 .
0 0 0 0 0 0 0 0 0
. 0 0 0 0 0 0 0 .
. . 0 0 0 0 0 . .
. . . 0 0 0 . . .
. . . . 0 . . . .
Sample Input 2
4
Sample Output 2
. . . 0 . . .
. . 0 0 0 . .
. 0 0 0 0 0 .
0 0 0 0 0 0 0
. 0 0 0 0 0 .
. . 0 0 0 . .
. . . 0 . . .
Sum of N terms in Harmonic series
Given integer
N as input, write a program to display the sum of the first N terms in harmonic series.
The series is: 1 + 1/2 + 1/3 + 1/4 + 1/5 ... + 1/N (N terms).
Input
The first line of input is an integer
N.
Output
Print the sum rounded upto 2 decimal places.
Explanation
For
N = 5
The sum of first 5 terms in harmonic series is 1 + 1/2 + 1/3 + 1/4 + 1/5
So, the output should be
2.28.
Sample Input 1
5
Sample Output 1
2.28
Sample Input 2
3
Sample Output 2
1.83
def character_element(n):
import string
if n in string.ascii_letters:
print('Letter')
elif n in string.digits:
print('Digit')
else:
print('Special Character')The Above code have two test cases, but they were not getting any expected output even one test case also. Please give me expected output. Thank you !
Question url link :-
https://drive.google.com/file/d/1iGIZxhoPoL67KNkroEgQpaIo3Vh8w7dE/view?usp=sharing
The test cases are below
Sample Input 1
9
Sample Output 1
Digit
Sample Input 2
A
Sample Output 2
Uppercase Letter
LARGEST PALINDROME
you are given an integer N . find the largest palindrome which is less than N .
INPUT
the input contains a single integer
OUTPUT
the output should be a single integer which is the largest palindrome that is less than the given input.
EXPLANATION
given N = 45
44 is the largest number which is a palindrome that is less than 45
SAMPLE INPUT 1
45
SAMPLE OUTPUT 1
44
SAMPLE INPUT 2
79
SAMPLE OUTPUT 2
77
You are given a positive integer N. Your task is to find the number of positive integers K <= N such that K is not divisible by any of the following numbers 2, 3, 4, 5, 6, 7, 8, 9, 10.
With Explanation too!