Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Must be done in Python (Latest Version) Please Answer all 5 Question. Question 1: Question 2 Question 3 Question 4 Question 5 Write a function

Must be done in Python (Latest Version)

Please Answer all 5 Question.

Question 1:

image text in transcribed

Question 2

image text in transcribed

Question 3

image text in transcribed

Question 4

image text in transcribed

Question 5

image text in transcribed

Write a function named addListValues0 which takes a list of values as well as two index positions as argument and returns the sum of the two values at the specified index positions. For example, if the list is: mylist = [4,2,6,7,8,1 ], then the function call add_list_values(myList, 2, 4) should return the value 14 A couple of things could go wrong here. Firstly, if a sequence subscript is out of range, then an IndexError will be generated. And of course, unless both operands are numeric, then a TypeError will occur indicating that the the addition could not be completed. Please note: 1. If an IndexError occurs, then the function should return 0. 2. If a TypeError occurs, then the function should return the string concatenation of the two values. For example: Test Result myList [4,2,6,7,-2,100 printCaddListValues(myList, 2, 4)) 4 myList -[4,2,6,7,"a",100] print(addListValues(myList, 2, 4)) 6a myList - [4,2,6,7,-6,100] print(addListValues(myList, 2, -400))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions