Skip to main content

Posts

Python Hacker Rank question and answer -- String 01

Python - String Operations - 1   Define a function `stringoperation` that takes four parameters, namely 'fn', 'ln', 'para' as a string, and 'number' as an integer.   The function definition code stub is given in the editor. Generate the print statements based on the condition given as follows: First print: concat 'fn', 'number' times the number of newline character and 'ln' Second print: 'concat' 'fn' , tab space and 'ln' Third print: Prints the 'number' multiples of the string 'fn' Fourth print: Prints the 'para' string using f-string as follows: The sentence is {para}   Input Format for Custom Testing   The input from stdin will be processed as follows and passed to the function:   The first line contains a string 'fn' , the first name. The second line contains a string 'ln' , the last name. The third line contain...
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.Mult...

HackerRank Hands-on - Using float

Python - Using Float 1   Sanjay is trying to help vijay to find the Area of a Triangle. But for some reason he is trying to find some relation between area and pi. let's help him find that based on the condition below. Function `triangle` takes three parameters called `n1`,'n2' as float and 'n3' as integer. Formula for Area:(n1*n2) /2 Return both values Area and Pi rounded off to 'n3' decimal places. NOTE: You can get the value of pi from math module.   Input Format for Custom Testing:   Input from stdin will be processed as follows and passed to the function.   The first line contains an float  n1 , the Height of the triangle. The second line contains an float  n2 , the base of the triangle. The third line contains an integer 'n3' which specifies the number of decimal places to be rounded off.   Sample Case 0 Sample Input STDIN      Function -----     ...

Hacker Rank using int math opeartor

Area & Volume   Sunil had an assignment on "Areas & Volumes" given by his Mathematics Teacher.He was given 1.' Side ',from which he have to find - Area of Square & - Volume of Cube 2.' Radius '   ,from which he have to find - Area of Circle & - Volume of Sphere 3." pi " equals to 3.14   Write the function definition for the function '' Integer_Math " which takes two arguments ' Side ' and ' Radius '   Print the Areas and Volumes as per the Sample Test Case below.   Input Format for Custom Testing: # In the first line, value for 'Side' # In the second line, value for 'Radius'   Note: -The outputs must be rounded off to two decimal places -Use round() for rounding off     -Example : round(123.45555, 2) is 123.46   Sample Test Case 1:   Sample Input STDIN      Function parameter -----      ------------------ 5 → Side 7 ...

HackerRank Handson - Python - Using Int operations

Python - Using Int operations   Define a function called ` find`  which takes three parameters .  The first parameter is ` num1 ` , the second parameter is ` num2` and the last parameter is 'num3' .   The function definition code stub is given in the editor. Print the output of comparison of the numbers in the parameters based on condition given below:   In the First print statement check if num1<num2 and num2>=num3 In the Second print statement check if num1>num2 and num2 <=num3 In the Third print statement check if num3==num1 and num1!=num2 Every output must be separated by a single space.   Constraints The output must be of boolean format. Input Format Format for Custom Testing   In the first line  num1  given In the second line  num2  given In the second line  num3  given     Sample Case 0   ...

Python Hacker Rank question and answer --Hands-on - Using int

Python - Integer   Write the function definition for the function ' Integer_fun ' which takes two parameters ' a' & ' b'  where  - a is a FLOAT variable & - b is a STRING variable which takes Integer input but as a String, Say b = "100".   Using type conversion, - Covert ' a ' into an INTEGER and store it in ' c ' - Covert ' b ' into an INTEGER and store it in ' d '    The Expected output is as below :  Print the Type of a  Print the Type of b Print c Print d Print the Type of c Print the Type of d   Input Format for Custom Testing: # In the first line, value for 'a' # In the second line, value for 'b'   Sample Test Case 1:   Sample Input STDIN      Function parameter -----      ------------------ 1.23 → a 562 → b   Sample Output <class 'float'> <class 'str'> 1 562 <class 'int...

Python Hacker Rank question and answer --Hands-on - Usage Imports

Python - Usage imports   Define a function called ` calc` which takes one parameter . The parameter 'c' is an integer which is the circumference of the circle .   The function definition code stub is given in the editor. Find the radius and Area of the circle using math module based on condition given below:   Formula for Radius: Area:   Return both Radius and Area.   The values must be rounded off to 2 positions. Constraints input must be an integer. Input Format Format for Custom Testing   In the first line c   given. Sample Case 0   Sample Input STDIN      Function -----      -------- 8       → c = 8 Sample Output (1.27, 5.09)  Explanation With 8 as input, Radius and Area are calculated and returned.   Answer: #!/bin/python3 import  math impor...