Skip to main content

Math Operations - Float

 

Rakul started learning Python3 to participate in the upcoming "CodeChamp" which is an University level coding competition which can provide some special privileges in the recruitment drives for the next 2 years only for those who make it to the "Top-100".His enthusiasm started falling when he find it difficult to understand the Mathematical operations involving "FLOAT".Help him to understand that easily.

 

Write the function definition for the function "Float_fun" which takes three parameters

- 'f1' which is a FLOAT Variable

- 'f2' which is also a FLOAT Variable &

- 'Power' is an INTEGER

 

Do the following and Print the Output as per the Sample Test Case :

1.Print "#Add"

2.Add 'f1' and 'f2' and Print it

3.Print "Subtract"

4.Subtract 'f2' from 'f1' and Print it

5.Print "Multiply"

6.Multiply 'f1' and 'f2' and Print it

7.Print "Divide"

8.Divide 'f2' by 'f1' and Print it

9.Print "Remainder"

10.Find the Modulus/Remainder of 'f1' by 'f2' and Print it

11.Print "#To_The_Power_Of"

12.Find 'f1' to the power of 'Power' and Print it

13.Print "Round"

14.Round the 12th value upto 4 decimal places and Print it

 

Input Format for Custom Testing:

# In the first line, value for 'f1'

# In the second line, value for 'f2'

# In the third line, value for 'Power'

 

Sample Test Case 1:

 

Sample Input

STDIN      Function parameter
-----      ------------------
10.75  →   f1
5.45   →   f2
3      →   Power  

 

Sample Output

#Add
16.2
#Subtract
5.3
#Multiply
58.5875
#Divide
0.5069767441860465
#Remainder
5.3
#To_The_Power_Of
1242.296875
#Round
1242.2969

 






#!/bin/python3

import math
import os
import random
import re
import sys



#
# Complete the 'Float_fun' function below.
#
# The function accepts following parameters:
#  1. FLOAT f1
#  2. FLOAT f2
#  3. INTEGER Power
#

def Float_fun(f1, f2, Power):
    # Write your code here
    print("#Add")
    print(f1+f2)
    print("#Subtract")
    print(f1-f2)
    print("#Multiply")
    print(f2*f1)
    print("#Divide")
    print(f2/f1)
    print("#Remainder")
    print(f1 % f2)
    print("#To_The_Power_Of")
    print (f1 ** Power)
    print("#Round")
    print(round((f1 ** Power),4))

if __name__ == '__main__':
    f1 = float(input().strip())

    f2 = float(input().strip())

    Power = int(input().strip())

    Float_fun(f1, f2, Power)

Comments

Popular posts from this blog

Python Hacker Rank Question and Answer -- Hands-on - Range

Python - Range1   Define a function called ` rangefunction ` which takes three parameters . The first parameter is ` startvalue ` , the next parameter is ` endvalue` and the last parameter is 'stepvalue' .   The function definition code stub is given in the editor. Generate the squares of numbers from ` startvalue ` to ` endvalue ` using range   based on condition given below:   Print the values which must be separated by tab spaces. Note: startvalue and endvalue both are inclusive in the range.    Constraints 1 ≤ startvalue Input Format for Custom Testing   In the first line  startvalue given In the second line endvalue given In the second line stepvalue given     Sample Case 0   Sample Input STDIN      Function -----      -------- 2       → startvalue = 2 9 → endvalue = 9 2 → ...

Python Hacker Rank Question and Answer -- Hands-on - Namespaces

  Python - Namespaces Write the function definition for the function  ' Assign ' to assign the different types of variables in its parameters to new variables. Parameters: 1.An INTEGER in the variable ' i ' 2.A FLOAT in the variable ' f ' 3.A STRING in the variable ' s ' 4.A BOOLEAN in the variable ' b '   New Variables to be assigned with : 1.An INTEGER in the variable ' w ' 2.A FLOAT in the variable ' x ' 3.A STRING in the variable ' y ' 4.A BOOLEAN in the variable ' z '   Assign the parameter variables  Respectively . and Print these in the following order: 1.w 2.x 3.y 4.z 5.Display all the objects defined in the current namespace by using the 'dir' function   Input Format for Custom Testing: # In the first line, value for ' i ' # In the second line, value for ' f ' # In the third line, value for ' s ' # In the fourth line, value for ' b '   Sample Test Case 1:   Sampl...

Python Hacker Rank question and answer --HandsOn -- Print

Greeting Quote Mr.Greet is the name of the digital notice board placed at the entrance of the seminar hall.Its purpose is to welcome each and every participants of the seminar by showing a welcoming quote with their name on it. It is based on the function ‘ Greet ’ which takes a single parameter ‘ Name ’ as a String are the names of the participants as Input One by one. Write the function definition for ‘ Greet ’ which will generate the welcoming quote as below : For Example,the ‘ Name ’ is “Ramakrishnan” then the welcoming quote will be : Output: Welcome Ramakrishnan. It is our pleasure inviting you. Have a wonderful day.   Note: ‘ Name ’ must be of String Data type.   Input Format for Custom Testing: It’s a single line contains a name. Sample Test Case 1:   Sample Input STDIN      Function -----      -------- Karthik → Name Sample Output Welcome Karthik. It is our pleasure inviting yo...