Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def range_roller(n,k): # start your code below this line -- make more lines if needed if K == 0: return list(range(N, 2*N+2, 3)) elif K

image text in transcribed

image text in transcribed

def range_roller(n,k): # start your code below this line -- make more lines if needed if K == 0: return list(range(N, 2*N+2, 3)) elif K == 1: return list(range(N, -1, -2)) else: return -1

# finish your code above this line

def while_it(): # start your code below this line -- make more lines if needed result = [] i = 105 while i >=7: result=result+[i] i=i-7 return result

# finish your code above this line

def num_sum(n): # start your code below this line -- make more lines if needed total_sum = 0 while N > 0: total_sum += N % 10 N = N // 10 return total_sum

# finish your code above this line

def greatest_integer(a,b,c):

# start your code below this line -- make more lines if needed if A > B and A > C: largest = A elif B > C: largest = B else: largest = C if A

return [largest, smallest]

# finish your code above this line def square_pair(list1,list2): # start your code below this line -- make more lines if needed if len(first_list) != len(second_list): return -1 result = [] i=0 while i

# finish your code above this line def main(): print(range_roller(9,0)) print(range_roller(11,1)) print(num_sum(984)) print(num_sum(21)) print(while_it()) print(greatest_integer(100,3,1)) print(greatest_integer(3,4,4)) print(square_pair([1,4,2],[1,16,4])) print(square_pair([3,5,1],[9,25]))

main()

image text in transcribed

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) : Ien () 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 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 iminimum 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 retums a list of the series, 105.98.91,...7. Constraint: You have to use a while loop to implement this Input: (984) Output: 21 Input: (21) Output: 3 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] 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 In [1]: runfile('/Users/jeongjongmin/Downloads/L3_Kahn_Dan_dzk54321-1.py', wdir='/Users/jeongjongmin/ Downloads') Traceback (most recent call last): File "/Users/jeongjongmin/Downloads/L3_Kahn_Dan_dzk54321-1.py", line 83, in main() File "/Users/jeongjongmin/Downloads/L3_Kahn_Dan_dzk54321-1.py", line 73, in main print(range_roller(9,0)) File "/Users/jeongjongmin/Downloads/L3_Kahn_Dan_dzk54321-1.py", line 10, in range_roller if K =0 : NameError: name 'K' is not defined In [2]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

Describe key customer feedback collection tools.

Answered: 1 week ago

Question

Know what customers expect from the firm when they complain.

Answered: 1 week ago

Question

Understand why customers complain.

Answered: 1 week ago