List: python’s basic concepts in lists


python’s basic concepts in lists
Write a python program list_basics_YI.py

  1. Creating a list.
  2. add elements to a list
  3. access a list’s values by iteration
  4. access a list’s values by index
  5. modify elements in a list
  6. add all elements in a list
  7. assign 100 random integer numbers between 1 and 100 to a new empty list, new_list
# 1. Creating a list.

a_list = []    # create empty list

# 2. add elements to a list
for number in range( 1, 11 ):
   a_list += [ number ]

print ("The values of a_list are:", a_list )  

# 3. access a list's values by iteration
print ("\nAccessing values by iteration:")

for item in a_list:
   print (item,end='')
print("\n")

# 4. access a list's values by index
print ("\nAccessing values by index:")
print ("Subscript   Value")

for i in range( len( a_list ) ):
   print ("%9d %7d" % ( i, a_list[ i ] ))

# 5. modify elements in a list
print ("\nModifying a list value...")
print ("Value of aList before modification:", a_list)
a_list[ 0 ] = -100   
a_list[ -3 ] = 19
print ("Value of aList after modification:", a_list)

# 6. add all elements in a list
total = 0
for i in range( len( a_list ) ):
   total += a_list[i]
print ("the sum of all items in the list is ", total)


# 7. assign random integer numbers between 1 and 100 to a new empty list, new_list

Required Submission
1. Copy and paste the programs in the Text Entry tab.
2. Submit the list_basics_YI.py or the repl.it link.
NOTE: Documentation
Header:

a) Assignment description ( you can copy and paste the assignment itself)
b) Author’s name
c) Language and version
d) Date of completion
Input/Output:
Input(If any) and output for each part.