Part One - Using a main function, Docstrings Write a function called hello. The function has no arguments and no return value. It simply prints the text "Hello World". Include a docstring that describes the function. Write a main function, as described by the Python main function reading. Call main, as described by the Python main function reading. From main, call hello and then print hello's docstring. Part Two - Error Handling Write a function called printListElement. The function has two arguments and no return value. The first argument is a list, and the second argument is a list index. The function will print an element from the list as determined by the list index. If the list index is invalid, print an error message We could accomplish this with a logic test, but instead, we will manage this with error handling. Write a try block that attempts to print the list element. Catch any errors with an except block, print From main, create a myList list with elements 0, 1, 2 by using the list and range commands. Then, call printListElement with your list and a list index value of 3. Part Three - How Python function arguments are treated There can be some confusion as to how Python functions treat their arguments - is it by reference or by value? Explore this for yourself. From main, create a myint variable and give it the value 3. Also create a myList list with elements 0, 1, 2 Print the IDs of myInt and myList. Also print the ID of the last element of myList. Now create a function called by Val which has one argument. In the function, add 7 to the argument. Print the ID of the argument before and after the change. Create a second function called byRef which has one argument. In the function, add 7 to the last element in the list. Print the ID of the argument and the ID of the last element of the argument before and after the change. Now call by Val with myInt and then call byRef with myList. Next, again print the IDs of MyInt, myList, and the last element of myList. Finally, print myInt and MyList from main. Can you explain the results? Here are two sites that do a good job of explaining how Python functions work: Is Python call by reference or call by value error message.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

can you wite the in pyth ,please?

Part One - Using a main function, Docstrings
Write a function called hello. The function has no arguments and no return value. It simply prints the text "Hello World". Include a docstring that describes the function.
Write a main function, as described by the Python main function reading.
Call main, as described by the Python main function reading.
From main, call hello and then print hello's docstring.
Part Two - Error Handling
Write a function called printListElement. The function has two arguments and no return value. The first argument is a list, and the second argument is a list index. The function will print an element from the list as determined by the list index. If the list index is invalid, print an error message.
We could accomplish this with a logic test, but instead, we will manage this with error handling.
Write a try block that attempts to print the list element. Catch any errors with an except block, print an error message.
From main, create a myList list with elements 0, 1, 2 by using the list and range commands.
Then, call printListElement with your list and a list index value of 3.
Part Three - How Python function arguments are treated
There can be some confusion as to how Python functions treat their arguments - is it by reference or by value? Explore this for yourself.
From main, create a myInt variable and give it the value 3. Also create a myList list with elements 0, 1, 2.
Print the IDs of myInt and myList. Also print the ID of the last element of myList.
Now create a function called byVal which has one argument. In the function, add 7 to the argument. Print the ID of the argument before and after the change.
Create a second function called byRef which has one argument. In the function, add 7 to the last element in the list. Print the ID of the argument and the ID of the last element of the argument before and after the change.
Now call by Val with myInt and then call byRef with myList. Next, again print the IDs of MyInt, myList, and the last element of myList. Finally, print myInt and MyList from main. Can you explain the results?
Here are two sites that do a good job of explaining how Python functions work:
Is Python call by reference or call by value
Parameters and Arguments
Transcribed Image Text:Part One - Using a main function, Docstrings Write a function called hello. The function has no arguments and no return value. It simply prints the text "Hello World". Include a docstring that describes the function. Write a main function, as described by the Python main function reading. Call main, as described by the Python main function reading. From main, call hello and then print hello's docstring. Part Two - Error Handling Write a function called printListElement. The function has two arguments and no return value. The first argument is a list, and the second argument is a list index. The function will print an element from the list as determined by the list index. If the list index is invalid, print an error message. We could accomplish this with a logic test, but instead, we will manage this with error handling. Write a try block that attempts to print the list element. Catch any errors with an except block, print an error message. From main, create a myList list with elements 0, 1, 2 by using the list and range commands. Then, call printListElement with your list and a list index value of 3. Part Three - How Python function arguments are treated There can be some confusion as to how Python functions treat their arguments - is it by reference or by value? Explore this for yourself. From main, create a myInt variable and give it the value 3. Also create a myList list with elements 0, 1, 2. Print the IDs of myInt and myList. Also print the ID of the last element of myList. Now create a function called byVal which has one argument. In the function, add 7 to the argument. Print the ID of the argument before and after the change. Create a second function called byRef which has one argument. In the function, add 7 to the last element in the list. Print the ID of the argument and the ID of the last element of the argument before and after the change. Now call by Val with myInt and then call byRef with myList. Next, again print the IDs of MyInt, myList, and the last element of myList. Finally, print myInt and MyList from main. Can you explain the results? Here are two sites that do a good job of explaining how Python functions work: Is Python call by reference or call by value Parameters and Arguments
Sample Execution Results:
Hello world
Help on function hello in module __main__:
hello()
This function prints Hello World
Error: bad index number.
Original ID of myInt in main is 1406102608
Original ID of myList in main is 2884791210120
Original ID of myList's last element in main is 1406102576
Original ID of parameter in byVal 1406102608
ID of parameter in byVal after change 1406102832
Original ID of parameter in byRef 2884791210120
Original ID of parameter's last element in byRef 1406102576
ID of parameter in byRef after change 2884791210120
ID of parameter's last element in byRef after change 1406102800
ID of my Int in main after call to byVal is 1406102608
ID of myList in main after call to byRef is 2884791210120
ID of myList's last element in main after call to byRef is 1406102800
myInt is now: 3
myList is now: [0, 1, 9]
Add the following at the end of the script to show your results:
Execution results:
paste execution results here
Transcribed Image Text:Sample Execution Results: Hello world Help on function hello in module __main__: hello() This function prints Hello World Error: bad index number. Original ID of myInt in main is 1406102608 Original ID of myList in main is 2884791210120 Original ID of myList's last element in main is 1406102576 Original ID of parameter in byVal 1406102608 ID of parameter in byVal after change 1406102832 Original ID of parameter in byRef 2884791210120 Original ID of parameter's last element in byRef 1406102576 ID of parameter in byRef after change 2884791210120 ID of parameter's last element in byRef after change 1406102800 ID of my Int in main after call to byVal is 1406102608 ID of myList in main after call to byRef is 2884791210120 ID of myList's last element in main after call to byRef is 1406102800 myInt is now: 3 myList is now: [0, 1, 9] Add the following at the end of the script to show your results: Execution results: paste execution results here
Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY