Question
for python, i have some ideas on how to approach it but not sure. any suggestions help! thank you.
4 is sorted (head) This function takes a single parameter, which is a list, and returns True or False, indicating whether or
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#list initialization
numList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

#method to check if list is sorted or not
def is_sorted(head):
list1 = head[:]
list1.sort()
if list1 == head:
return True
else:
return False

#method to find the sum of the list
def list_sum(head):
total = 0
for i in range(len(head)):
total = total + head[i]
return total

#check if list is sorted
if is_sorted(numList):
print("The list is sorted")
else:
print("The list is not sorted")
  
#display the sum of the list
print("The sum of the list is:",list_sum(numList))

The screenshot of the above source code is given below:

#list initialization numList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] #method to check if list is sorted or not def is_sorted(head):

OUTPUT:

The list is sorted
The sum of the list is: 55


Add a comment
Know the answer?
Add Answer to:
for python, i have some ideas on how to approach it but not sure. any suggestions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the following linked list structure called node: struct node { int val; struct node *...

    Given the following linked list structure called node: struct node { int val; struct node * ptrNext; }; Assume we have a single list created from this structure with a head pointer called ptrFirst which is declared in the global scope. a. Write a complete C function called CountEven to count all the even values in this singly linked list of arbitrary number of nodes using an iterative (non-recursive) approach. The function takes as parameter the pointer to the starting...

  • Python 3 Coding Functions: Here is any code required to help code what is below: def...

    Python 3 Coding Functions: Here is any code required to help code what is below: def pokemon_by_types(db, types): new_db = {} for pokemon_type in types: for key in db: # iterate through all the type in types list if db[key][1] == pokemon_type or db[key][2] == pokemon_type: if key not in new_db: new_db[key] = db[key] return new_db I need help coding the functions listed below in the image: Thank you get types(db): Given a database db, this function determines all the...

  • How to do this code? HW13.11. Create an HTML list from a Python list The function...

    How to do this code? HW13.11. Create an HTML list from a Python list The function below takes one parameter: a list, that contains only strings. Complete the function to create a unordered HTML list, as a string, and returns it. An empty list should return an empty HTML list with no list items. Do not add any extraneous whitespace to the HTML. For example, if given the list ["one", "two"], the function should return "<ul><li>one</li><li>two</li> </ul>". student.py IT TI...

  • python 11.47 Lab Exam 3 - Column Sums This section has been set as optional by your instructor. Write a Python function...

    python 11.47 Lab Exam 3 - Column Sums This section has been set as optional by your instructor. Write a Python function column_sums() that takes a nested list as a parameter, and returns a single list where each entry corresponds to the sum of the list's column contents. Sample Function Call: nested [[1, 2, 3], [1, 2, 31, [1, 2 ]] column sums (nested) Expected Return: [3, 6, 6] 11.47 Lab Exam 3 - Column Sums This section has been...

  • I need help asap, Python language 2) Write a class to represent a class to represent...

    I need help asap, Python language 2) Write a class to represent a class to represent a Car and its passengers. Write a constructor that takes one additional parameter a number, the total seats in the car. The constructor should save this as a datamember and also initialize an additional datamember, a list, to keep track of the passengers in the car. Write method addRider that takes an additional parameter a string of the passenger to be added to the...

  • Python Program 5. Write a Python program in a file named validTime.py. Include a function named...

    Python Program 5. Write a Python program in a file named validTime.py. Include a function named string parameter of the form hh:mm: ss in which these are numeric validTime that takes a values and returns True or False indicating whether or not the time is valid. The number of hours, minutes, and seconds must two digits and use a between 0 and 9). The number of hours must be between 0 and 23, the number of minutes and seconds must...

  • in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all...

    in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all the items in the tuple are integers(2), and returns False otherwise. For example, contains_only_integers (3, 5, 17, 257, 65537) ), contains_only_integers( (-1,) ), and contains_only_integers( ) should all return True, but contains_only_integers (2.0,4.0)) and contains_only_integers (8, 4, "2", 1)) should both return false. Your function should use a while loop to do this calculation. 121 Hint: the is instance() built-in function provides the most...

  • Hi, I have programming problem related to array, sorting, and. swap operation Thank you, Best Regards.....

    Hi, I have programming problem related to array, sorting, and. swap operation Thank you, Best Regards.. A non-empty array A consisting of N integers is given. You can perform a single swap operation in array A. This operation takes two indices I and J, such that 0 S13 J<N, and exchanges the values of A[i] and A[J]. The goal is to check whether array A can be sorted into non-decreasing order by performing at most one swap operation. For example,...

  • This is Python coding question, and topic is recursive. Can anyone help me figuring this out?...

    This is Python coding question, and topic is recursive. Can anyone help me figuring this out? (Only recursive function is allowed.) Thanks. Write a function called Fibonacci(n) that takes as a parameter an integer n and returns the nth Fibonacci number. The first two Fibonacci numbers are 1 and every subsequent one is the sum of the previous two: 1, 1, 2, 3, 5, 8, 13, .... Write a recursive function to count the number of uppercase letters in a...

  • I need help and have to get this done asap: Using the following source codes provided below, create recursive functions...

    I need help and have to get this done asap: Using the following source codes provided below, create recursive functions and methods in C++ to complete the following exercises: Print the list in forward order Print the list in reverse order Print the following three lines (in this order): "The first node contains <value in first node>" "The last node contains <value in last node>" "The first node contains <value in first node>" Print the sum of all the values...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT