Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from List import *
- def main():
- arr = eval(input("Enter an array of integers: "))
- strings = ArrayToList(arr)
- integers = ListMap(int, strings)
- print("The list of integers:")
- printList(integers)
- smallest, index = minimumList(integers)
- print("The smallest value in the list:", smallest, "and it exists at:", index)
- subList = getSubList(integers, index)
- print("The sublist:")
- printList(subList)
- s = sumList(subList)
- print("Sum of sublist:", s)
- def sumList(lst):
- s = 0
- spot = lst
- while (spot != None):
- s += head(spot)
- spot = tail(spot)
- return s
- def getSubList(lst, index):
- spot = lst
- for i in range(0, index, 1):
- spot = tail(spot)
- return tail(spot)
- def minimumList(lst):
- count = 0
- index = 0
- smallest = head(lst)
- spot = tail(lst)
- while (spot != None):
- if (head(spot) < smallest):
- smallest = head(spot)
- index = count
- count += 1
- spot = tail(spot)
- return smallest,index+1
- def printList(lst):
- spot = lst
- while (spot != None):
- print(head(spot))
- spot = tail(spot)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement