
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Python code please, indentation would be greatly appreciated
![Write a function named slice_it (numbers_list, index) that takes a list and an integer as parameters. The function should
divide the list into two new lists, the first list going up to (but not including) the parameter index, and the second list going from
the index up to (and including) the end of the list. The index can be zero, positive or negative. If the index is invalid (i.e. out of
range), the function should print "Invalid index". Otherwise, the function should print the list with the most elements. If both
lists are the same length, then the function should print the first list followed by the second list on the next line.
For example:
Test
Result
slice_it([1, 2, 3, 4, 5], 2)
[3, 4, 5]
slice_it([1, 2, 3, 4, 5], -6)
Invalid index.
slice_it([1, 2, 3, 4, 5], 5)
Invalid index
slice_it([1, 2, 3, 4, 5, 6], 3)
[1, 2, 3]
[4, 5, 6]
slice_it([1, 2, 3, 4, 5, 6, 7, 8], -3) [1, 2, 3, 4, 5]](https://content.bartleby.com/qna-images/question/f64c4370-50a6-4b0a-be8f-9aa36b172cbb/0679eb33-1ae0-49f5-b307-39c3718b6b48/z7c1gus_thumbnail.png)
Transcribed Image Text:Write a function named slice_it (numbers_list, index) that takes a list and an integer as parameters. The function should
divide the list into two new lists, the first list going up to (but not including) the parameter index, and the second list going from
the index up to (and including) the end of the list. The index can be zero, positive or negative. If the index is invalid (i.e. out of
range), the function should print "Invalid index". Otherwise, the function should print the list with the most elements. If both
lists are the same length, then the function should print the first list followed by the second list on the next line.
For example:
Test
Result
slice_it([1, 2, 3, 4, 5], 2)
[3, 4, 5]
slice_it([1, 2, 3, 4, 5], -6)
Invalid index.
slice_it([1, 2, 3, 4, 5], 5)
Invalid index
slice_it([1, 2, 3, 4, 5, 6], 3)
[1, 2, 3]
[4, 5, 6]
slice_it([1, 2, 3, 4, 5, 6, 7, 8], -3) [1, 2, 3, 4, 5]
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 2 images

Knowledge Booster
Similar questions
- when assigning variable names in python, what must we do to create a copy of the data?arrow_forwardReview Key Terms/Concepts: Pseudocode Variable Convention Loop Counting Indentation Repeating Buggy Condition Branch Listen: In this video you saw programmer develop pseudocode. Pseudocode is English like syntax that resembles a programming language. Research: Find examples of pseudocode online to support your understanding of pseudocode. Build: Develop pseudocode for your Project 1: Caesar Cipher program. Submit this for a grade.arrow_forwardPython learning object : Function creation Character multiplication (a * 5 == aaaaa) Using len function In the code I should also define __name__ == '__main__'arrow_forward
- In PYTHON Using one of the loop construct draw:- A square- Side length: 10 units (or pixels) Assumption- Use of Turtle libraryarrow_forwardQuestion - 3) Using Visual studio demonstrate types of Errors in C#: (Submission Instruction: Take the screenshots of those errors and paste in the MS Word file and explain the cause of errors and how you can fix them) You may use the same project which you used in Question to show how can errors may occur and how you fix them. Types of errors you should demonstrate are : Syntax errors Runtime Errors Logical Errors [ 3| Pagearrow_forwardprogramming language please answer this question asap thank you :)arrow_forward
- Barcode Validation As you are aware, barcodes encode numbers. In the Universal Product Code system, each item is assigned a globally unique number. But not every number is a valid UPC. Why? Part of the answer is the check digit. In order to catch errors, the rightmost digit is calculated from the others. If this digit does not match its expected value, you can be assured the barcode is invalid, or has been read incorrectly. To calculate the check digit, perform the following operations modulo 10: • Sum the digits in the odd positions and multiply the result by three. • Add the digits in the even positions to the result. • Subtract the result from 10 to obtain the check digit. Your Task Given a 12-digit UPC, you will need to identify whether is is valid or invalid. The code will be provided from standard input. You simply need to print "valid" or "invalid" in response. Notes The code will be provided on a line by itself, and will consist of numerals alone. You may assume that it will be…arrow_forwardplease demonstrate in vs code and send screenshotsarrow_forwardCode to _develop software using a regular expression module to process the following phone numbers.you are to extract the area code,trunk, number, and optionally an extension for each number. You may use the regular expression module in the language of your choice, please note that we covered the syntax for Perl 5 which is imitated by python 3, javascript, C++, and C#. Java, too. 800-555-1212 800 555 1212 800.555.1212 (800) 555-1212 1-800-555-1212 800-555-1212-1234 800-555-1212x1234 800-555-1212ext. 1234 1-(800) 555.1212 #1234 Reporting: Demonstrate your results by outputting the extracted information for each input number. Your report should be one page and it should be include a discussion of your use of the regular expression module..arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY