Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE PYTHON!!!!!!!!! Part One Using a main function, Docstrings Write a function called hello. The function has no arguments andno return value. It simply

USE PYTHON!!!!!!!!!

Part One – Using a main function, Docstrings

Write a function called hello. The function has no arguments andno return value. It simply prints the text "Hello World". Include adocstring that describes the function.

Write a main function, as described by the Python main functionreading.

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 twoarguments and no return value. The first argument is a list, andthe second argument is a list index. The function will print anelement from the list as determined by the list index. If the listindex is invalid, print an error message.

We could accomplish this with a logic test, but instead, we willmanage this with error handling.

Write a try block that attempts to print the list element. Catchany errors with an except block, print an error message.

From main, create a myList list with elements 0, 1, 2 by usingthe list and range commands.

Then, call printListElement with your list and a list indexvalue of 3.

Part Three – How Python function arguments are treated

There can be some confusion as to how Python functions treattheir arguments - is it by reference or by value? Explore this foryourself.

From main, create a myInt variable and give it the value 3. Alsocreate a myList list with elements 0, 1, 2.

Print the IDs of myInt and myList. Also print the ID of the lastelement of myList.

Now create a function called byVal which has one argument. Inthe function, add 7 to the argument. Print the ID of the argumentbefore and after the change.

Create a second function called byRef which has one argument. Inthe function, add 7 to the last element in the list. Print the IDof the argument and the ID of the last element of the argumentbefore and after the change.

Now call byVal with myInt and then call byRef with myList. Next,again print the IDs of MyInt, myList, and the last element ofmyList. Finally, print myInt and MyList from main. Can you explainthe results?

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_2

Step: 3

blur-text-image_3

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

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions