Python Answers

Questions answered by Experts: 5 288

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

The volume of a sphere is 4/3πr3, where π has the value of "pi" given in Section 2.1 of your textbook. Write a function called print_volume (r) that takes an argument for the radius of the sphere, and prints the volume of the sphere.

Call your print_volume function three times with different values for radius.

Include all of the following in your Learning Journal:

  • The code for your print_volume function.
  • The inputs and outputs to three calls of your print_volume

Product of the String

You are given an alphanumeric string S.Write a program to multiply all the charcters(except trailing zeroes) in S and print the output.


Rules for multiplication:

  • If the character is digit, multiply its value.
  • If the character is an alphabetic character, multiply the product of digits of its ASCII value.

Input

The first line contains a string S.


Output

The output should be a integer denoting the product of characters.


Explanation

For N = 123a4


ASCII value of a is 97.

Product of digits of ASCII value of a is 9 *7 = 63.

Therefore the product of characters is 1*2*3*4*63*4 = 1512.


Sample Input1

123a4

Sample Output1

1512




write a python function Separate_List(A) (Refer RollNo_W8B_2.py ) which take list A as input and return five lists, one contains all prime numbers in A, second one contains composite numbers in A, the third list contains all numbers in A which are neither divisible by 2, fourth and fifth list contains number divisible by 3 and 5

While taking a viva class teacher decides to take the viva of 2 roll numbers at a time. For

this he calls out the roll numbers from the roll number list as: one roll no. from 1st nth roll number and 2nd roll number from the nth last roll number. For example if the numbers are

roll-num=[31,25,4,22,5,43,11,30,6,17] and n=3 the one roll number for viva is 4 and 2nd roll number for viva is 30. Give fixed input.


Narendra is given a list containing non-repetitive numbers. You need to write a python function se-L(X) which takes input list X and returns five lists , one contains all prime numbers in A , 2nd one contain composite numbers in A , the third list contains all in A which are divisible by 2 , 4th and 5th list contain numbers divisible by 3 and 5 respectively

For example if X = [1,2,3,4,5,12,25,30,37] then 1st list = [2,3,5,37] , 2nd list=[4,12,25,30]

3rd list=[2,4,12,30] , 4th list=[3,12,30] and 5th list=[5,25,30] . Specify input in fixed form.


You have given A and B as2 lists which may have repeated elements in respective list. Write a python function mg-L(A,B) which takes list A and B as input and returns a merged list. The function will merge the list B with A (means the list A will be expanded) such that the resultant A


still contain no duplicates. Specify input in fixed form. Use only list operations. For example if


A =[2,4,8,2,1] and B=[10,4,3,8,7] merged-list =[1,2,3,4,7,8,10]

While taking a viva in class, the teacher decides to take the viva of two roll numbers at a time. For this she calls out the roll numbers from the list of roll numbers as: One roll number from the first nth roll number and Second roll number from the nth last roll number. For example if the numbers are: rollnum=[21, 24, 45, 6, 7, 23, 9, 11, 15, 18], and n=4, then :One roll number called for viva is 6 and second roll number called for viva is 9.

You need to write a python function which take a list A and nth roll number as input and return first nth roll number and Second roll number from the nth last roll number as shown in example. If nth roll number is not lies in the range of list, then function will return "n is not in range" in place of first roll number and empty string (“”) in place of second roll number.

 

Example-1

Example-2

Input:

[21, 24, 45, 6, 7, 23, 9, 11, 15, 18]

20

 

Output:

n is not in range

Input:

[21, 24, 45, 6, 7, 23, 9, 11, 15, 18]

5

 

Output:

7

23



write a python function Separate_List(A) which take list A as input and return five lists, one contains all prime numbers in A, second one contains composite numbers in A, the third list contains all numbers in A which are neither divisible by 2, fourth and fifth list contains number divisible by 3 and 5 respectively.

 

Example-1

Example-2

Input:

1

2

3

4

5

10

15

20

30

 

Output:

[2, 3, 5]

[4, 10, 15, 20, 30]

[2, 4, 10, 20, 30]

[3, 15, 30]

[5, 10, 15, 20, 30]

Input:

1

3

5

6

7

8

9

10

 

Output:

[3, 5, 7]

[6, 8, 9, 10]

[6, 8, 10]

[3, 9]

[5, 10]



You have given A and B as two lists with may have repeated element in the respective list. Write a python function Merge_List(A, B) which take list A and B as input and return a merged list. The function will merge the list B with A (means the list A will be expanded) such that the resultant A still contain no duplicates.

 

Example-1

Example-2

Example-3

Input:

A:

 1

 2

 3

 4

 5

 

B:

 1

 1

 1

 11

 2

 3

Output:

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

Input:

A:

 1

 2

 3

 4

 5

 

B:

1

2

3

4

5

 

Output:

[1, 2, 3, 4, 5]

Input:

A:

 1

 2

 3

 

B:

4

5

 

Output:

[1, 2, 3, 4, 5]



Explain the debugging process and explain the debugging facilities available in the IDE.


LATEST TUTORIALS
APPROVED BY CLIENTS