Question

in python For a list of 100 items, the index of the last item is: (please...

in python
For a list of 100 items, the index of the last item is:
(please don't use negative indexing here...)
Answer:

Homework Answers

Answer #1
import random
random_no = random.sample(range(100), 100).   #created the 100 elements list
random_no                                     #printing the elements
random_no[len(random_no)-1]                   #accessed the last elements

I used random.sample to create a 100 elements list to show you how to retrieve the last element.

And accessed the last element using len() function minus 1. (because the indexing starts from 0).

I think this answered your question. If you still got any query. Do post in the comments.

Know the answer?
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
Similar Questions
In python.....Create a Linked List program using at least 15 items. Must use the following in...
In python.....Create a Linked List program using at least 15 items. Must use the following in your program: Min() Max() Index() Count() Remove() Note: Use the "print" statement after each method.
In Python define a function remove_indices which is given a list of items and a list...
In Python define a function remove_indices which is given a list of items and a list of indices to remove. Remove the given indices in place (no extra memory) in linear time
Can you please write this in python Thank you. Consider a list called A: A =...
Can you please write this in python Thank you. Consider a list called A: A = [-6, 10, 100, 5, -20, 1000, 9, -15] Make a for loop that iterates over A and: If number is negative, print the square of the number. if number is positive but less than or equal to 100, print the number itself. if number is positive but greater than 100, print 0.
1.Implement a function which will -       + Accept a number, num, and a list, my_list...
1.Implement a function which will -       + Accept a number, num, and a list, my_list as arguments       + return True if num exists in my_list       + return False otherwise 2. Write Python code to implement the following function - def find_in_list(item, my_list):     """     Look for an item from my_list (of items.)     If the item is found, return the index position of the item;     otherwise, return -1.     """       #add your code here...
Below is a list of items. indicate the item number and the line and section of...
Below is a list of items. indicate the item number and the line and section of the Balance Sheet that the item should be reported. (Example: assume there was an Item 8. Postage Stamps, the correct answer would be 8. Prepaid Expenses, Current Asset) Item 1. Compensating balances held for short-term borrowing arrangements Item 2. Savings account Item 3. Cash set aside as a bond sinking fund for bonds maturing in 3 years Item 4. Treasury bills with original maturing...
The last thing we will learn about in python is functions. Functions are a great way...
The last thing we will learn about in python is functions. Functions are a great way to organize your program - we use them to write code that is executed only under certain circumstances - for instance when you're using Amazon, any of the following are likely functions within their program: - Add item to cart, determine arrival date,  create a new address, compute taxes, compute shipping charges, charge credit card Because you can write a task-specific function once, and ensure...
(Python) ######new part: append method ######we have a list ##lis = [1,'a',8, 0] ##print(lis) ########to append...
(Python) ######new part: append method ######we have a list ##lis = [1,'a',8, 0] ##print(lis) ########to append "yes" to the list: ##lis.append('yes') ##print(lis) ########index method: let us find the index of 'yes': ##index_yes = lis.index('yes') ##print(index_yes) ## here you cam see that it is 4, as it must be ########insert method: we want to put 'o, no!' in the list at the first place: ##lis.insert(0, 'o,no!') ##print(lis) ########### sort method: we wnat to sort out list; for our regrets sorting is...
In python, Give an algorithm for finding the second-to-last node in a singly linked list in...
In python, Give an algorithm for finding the second-to-last node in a singly linked list in which the last node is indicated by a next reference of None.
Name the script for.sh.  This script will create a shopping list. Ask the user to enter items...
Name the script for.sh.  This script will create a shopping list. Ask the user to enter items separated by a space. Read the list. Use a for loop to write (use echo) the items to a file called shopping_list. You should use >> to append the output to the file, so each time the script is run the list should get longer. After the for loop finishes, display (use cat) the contents of the shopping list with 1 item per line....
Write a recursive function elemAt that returns the ith item of the list, where the first...
Write a recursive function elemAt that returns the ith item of the list, where the first item is index 0. You may not use any of the standard Haskell functions that operate on lists. For Example: List is [5,6,7,78,8,7]          Element at index 3 is 78
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT