Print (reduce( lambda x, y: x * y, range ( 1, n+ 1 )))ĭescription The given data frame 'customer' has a column 'Cust_id' which has values Cust_1, Cust_2 and so on. # This way, when the code reaches the end of the range, i.e. # define a lambda function with x and y and keep multiplying them using reduce(). # In all other cases, use reduce() between the range 1 and (n+1). # If n is zero, simply print 1 as this case can't be handles by reduce() Return reduce( lambda x,y:x*y, range ( 1 ,n+ 1 ))įact = reduce( lambda x, y: x*y, range ( 1, n + 1 )) if n> 0 else 0 if n = 0 else 'factorial not possible' P.S.: Finding the factorial without using the reduce() function might lead to deduction of marks. Note: Make sure you handle the edge case of zero. Second_name = n_list #write your answer hereĬustomer_code = n_list #write your answer hereĭescription Given a number ‘n’, output its factorial using reduce(). #first name will be the 2nd element (index 1) second name will be first element(index 0)įirst_name = n_list #write your answer here Print (second_name + " " + first_name+ " " +customer_code) Second_name = input_str #write your answer hereĬustomer_code = input_str #write your answer here Note that you need to print in the order first name, last name and customer code. In this example, second_name= 'Kumar', first_name= 'Ravi', customer_code = '003'.Ī sample output of the input 'Kumar_Ravi_003' is: Ravi Kumar 003 Description Split the string input_str = 'Kumar_Ravi_003' to the person's second name, first name and unique customer code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |