sum prime numbers in the input
given a list of integers, write a program to print the sum of all prime numbers in the list of prime numbers.
note.one is either prime nor composite number.
input
the input will be a single line containing space separated integers..
output
the output should be a single line containing the sum of all prime numbers from 1 to N
explanation
for example, if the given list of integers are
2 4 5 6 7 3 8
as 2,3,5 and 7 are prime numbers,your code should print the sum of these numbers. so the output should be 17
sample input 1
2 4 5 6 7 3 8
sample output 1
17
sample input 2
65 87 96 31 32 86 57 69 20 42
sample output 2
31
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.(Both M and N are inclusive.)
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 40, as all the prime numbers from 18 to 40 are 19,23,23,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 1
139
index of last occurrence
write s program to print the index of the last occurence 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 occurence 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 occurence, 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
sample output 2
11
first letters
you are given three strings are inputs. write a program to print the first character of each string.
input
the first,second and third lines of input are strings.
explanation
consider the given strings to be apple, banana and carrot.we need to consider the first character in each of these strings we get the character a from the string apple. we get the character b from the string banana. we get the character c from the string carrot. so the final output should be abc
sample input 1
apple
banana
carrot
sample output 1
abc
sample input 1
very
important
person
sample output 2
vip
compare last three characters
write a program to check if the three last characters in the given two strings are the same
input
the first and second lines of inputs are strings
output
the output should be either true or false
explanation
given strings are apple ,pimple. in both strings, the last three characters ple are commom
so the output should be true.
sample input 1
apple
pimple
sample output 1
true
sample input 2
meals
deal
sample output 2
faslse
write a program to find if a given number is positive or negative in python
Matrix Rotation
You're given a square matrix A of dimentions N X n. You need to apply below 3 operations.
Rotation: It is represented as R S where S is an integer in {90,180,270...} which denotes the number of degrees to rotate .You need to rotate the matrix A by angle S in the clockwise direction.
The angle of rotation S will always be in multiples of 90 degrees.
Update: It is represented as U X Y Z. In initial matrix A , you need to update the element at row index X and column index Y with value Z.
Querying: It is represented as Q K L.You need to print the value at row index K and column index L of the matrix of the matrix A.
Sample Input 1
2
1 2
R 90
Q 0 0
Q 0 1
R 90
Q 0 0
U 0 0 6
Q 1 1
-1
Sample Output 1
3
1
4
6
Sample Input 2
2
5 6
7 8
R 90
Q 0 1
R 270
Q 1 1
R 180
U 0 0 4
Q 0 0
-1
Sample Output 2
5
8
8
In Python programming, compute the circumference of a circle given the radius entered by the user. The circumference of the circle is calculated as follows: (5 Points) C= 2πr
10=x
1.Convert the 1-D array to 3-D array
a = np.array([x for x in range(32)])
Answer:
print(o)
Output:
array([[[ 0, 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, 27, 28, 29, 30, 31]]])
2.Convert the value in the array to appropriate data type
a = np.array([[7.2, 5.4, 9.3],
[3.8, 6.7, 8.5]])
Answer:
print(o)
Output:
[[7 5 9]
[3 6 8]]
3.Extract value in between 7 to 15 from the given array
a = np.array([2, 6, 1, 9, 10, 3, 27])
Answer:
print(o)
Output:
[ 8 12 9 11]