Question
Python Only Q.1 Write a function called range_roller( ) that takes in two parameters N and K , both as integers. The function should do
Python Only
Q.1 Write a function called range_roller( ) that takes in two parameters N and K, both as integers. The function should do the following using the range( ) function:
-Return a list of numbers from N to 2N+1 (maximum must not be greater than 2N+1) with step size=3, if and only if K=0
-Return a list of numbers from N to 0 (minimum must not be lesser than 0) with step size=2, if and only if K=1
-Return -1 if K is neither 0 nor 1
Two examples are shown below:
Input: (9, 0)
Output: [9, 12, 15, 18]
Input: (11, 1)
Output: [11, 9, 7, 5, 3, 1]
Q.2 Write a function called while_it( ) that takes in no parameters and returns a list of the series, 105,98,91,,7.
Constraint: You have to use a while loop to implement this
Q.3 Write a function called num_sum( ) that takes in an integer N as a parameter and computes the sum of digits of N using a while loop. The function should return the computed sum. Two examples are shown below:
Input: (984)
Output: 21
Input: (21)
Output: 3
Q4. Write a function called greatest_integer( ) that takes in three parameters (A,B,C) and uses logical operators to determine the largest and the smallest number among these three. The function should return the largest and the smallest number in the form of a list which is supposed to be arranged in descending order. Two examples are shown below:
Input: (100, 3, 1)
Output: [100, 1]
Input: (3, 4, 4)
Output: [4, 3]
Q5. Write a function called square_pair( ) that takes in two lists, namely first list and the second list as parameters. The first list would contain a series of integers and the second list would contain the squares of the integers in the first list, at corresponding indexes. The task is to construct and return a list, containing all corresponding pairs of integers and their squares positioned adjacently. Also entries in every pair should be visible in ascending order. Furthermore your function should return -1 if the two input lists are of distinct lengths. Two examples are shown below:
Input: ([1, 4, 2],[1, 16, 4])
Output: [1, 1, 4, 16, 2, 4]
Input: ([3, 5, 1],[9, 25] )
Output: -1
===================
Here is Template
You are NOT allowed to use the following constructs unless specified in the assignment directions. Using the following constructs will result in 0 (zero) for the entire submissio (assignment, timed test, etc.). The restricted items are as follows: - Concepts not discussed in lectures yet - String functions - Member functions - Exceptions (can use) : len () and x=x+[y1,y2,y3] - Built-in functions \& types - Exceptions (can use): str( ), readline( ), open( ), close( ), write( ), read( ), range( ), split( ) - Cannot use .append, sort, etc. - Cannot use "Slicing" - Cannot use "list comprehension" - Cannot use "not in" (together) - Cannot use "in" - not allowed with conditionals - Exception (can use): with range () - Cannot use and \{\} - Exception (can use): mathematical operations (multiply \& exponents) - Data type functions - Exceptions (can use): int(), str (), float () - Break - Continue - Nested Constructs - Exceptions (can use): 2-D list - Multiple returns \& Multiple assignments - Recursion (not allowed unless the question explicitly states otherwise) - Functions within functions (Definitions) -- invocation is fine - Default Parameters - Global variables - Keyword as variable names - while true or without proper condition
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started