Skip to main content

Posts

Showing posts with the label Python

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...

Python Hacker Rank question and answer --Hands-on - Namespaces 2

Python - Input from the user   Write the function definition for the function ' Prompt ' to get a ' STRING ' input from the user. Write a script to prompt the question " Enter an STRING: ". Pass the user input in a variable, Say 'x'.   Print the value of 'x' and its type in separate lines.   Input Format for Custom Testing: It’s a single line that contains string input from the user.   Sample Test Case 1:   Sample Input STDIN     ----- One Sample Output Enter a STRING: One <class 'str'>   #!/bin/python3 import  math import  os import  random import  re import  sys # # Complete the 'Prompt' function below. # # def  Prompt():      # Write your code here      print (  'Enter a STRING:' )     x = ''      print ( input (x))...

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...

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

Python Question And Answers  Question : Python - Get Additional Info   Define a function called ` docstring `  which takes one parameter .  The  parameter 'function-name' is a  Python  built-in function  name.   The function definition code stub is given in the editor. Generate a  Docstring of the input function  based on the condition given below:   The Docstring must give the maximum information about the function.     Constraints Input must be a string. Input Format Format for Custom Testing   In the input, any python built-in function is   given as a string.     Sample Case 0   Sample Input STDIN      Function -----      -------- print   → functionname = print Sample Output: Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream...