Search This Blog

Range1 - Define a function called `rangefunction` which takes three parameters-Hands on Python Range Hacker Rank Question and Answer. Course ID - 55193

 Python - Range1

 

Define a function called `rangefunctionwhich takes three parametersThe 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       →  stepvalue = 2

Sample Output

4    16    36    64   

Explanation

  • With 2 as startvalue to 9 as endvalue and with 2 as stepvalue the output is  2    4    6    8

        whose squares are 4    16    36    64

    Click on Image:


Answer:



#!/bin/python3

import math
import os
import random
import re
import sys


#
# Complete the 'func' function below.
#
# The function is expected to print an INTEGER.
# The function accepts following parameters:
#  1. INTEGER startvalue
#  2. INTEGER endvalue
#  3. INTEGER stepvalue
#

def rangefunction(startvalue, endvalue, stepvalue):
    # Write your code here
    list1 = list(range(startvalue,endvalue,stepvalue))
    for i in list1:
        val = i**2
        print(val, end="\t")    

if __name__ == '__main__':

    x = int(input().strip())

    y = int(input().strip())

    z = int(input().strip())

    rangefunction(x, y, z)

1 comment:

  1. l=[]
    for i in range(startvalue,endvalue+1):
    l.append(i)

    print(l[:3])
    print(l[-1:-6:-1])
    print(l[::4])
    print(l[-1::-2])

    "second range Handson answer of python"

    ReplyDelete

If you have any doubts, Please let us know.