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 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...
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....
Python Implement function swapFL() that takes a list as input and swaps the first and last...
Python Implement function swapFL() that takes a list as input and swaps the first and last ele- ments of the list. You may assume the list will be nonempty. The function should return the new list. >>> ingredients = ['flour', 'sugar', 'butter', 'apples'] >>> swapFL(ingredients) >>> ingredients ['apples', 'sugar', 'butter', 'flour']
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
(((Python))) How can we use a LIST in a sequence or an IF Statement? Do we...
(((Python))) How can we use a LIST in a sequence or an IF Statement? Do we create a list, like in a Tuple, or can we ask a user for a set of items to add into our list? Give some examples if you can.
Please create a function with python to read a mixed numeric/alphabetic (strings) list and then outputs...
Please create a function with python to read a mixed numeric/alphabetic (strings) list and then outputs the following: The sum of the numeric values in the list A count of the non-numeric values in the list
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT