``````# Generates a list of 10 random numbers between 0 and 20 included,
# and determines the length of the longest strictly increasing sequence and
# the smallest most frequent element in the list.
#
# Writtten by Eric Martin for COMP9021

import sys
from random import seed, randint

nb_of_elements = 10

try:
seed(input('Enter an integer: '))
except TypeError:
print('Incorrect input, giving up.')
sys.exit()

L = []
for _ in range(nb_of_elements):
L.append(randint(0, 20))
print('The generated list is:', L)

length_of_longest_increasing_sequence = 1
current_length = 1

smallest_most_frequent = None
largest_count = 0

for i in range(nb_of_elements - 1):
if L[i] < L[i + 1]:
current_length += 1
else:
if current_length > length_of_longest_increasing_sequence:
length_of_longest_increasing_sequence = current_length
current_length = 1
if current_length > length_of_longest_increasing_sequence:
length_of_longest_increasing_sequence = current_length

L.sort()
for e in L:
count = L.count(e)
if count > largest_count:
largest_count = count
smallest_most_frequent = e

print('The length of the longest strictly increasing sequence is: {}'.format(
length_of_longest_increasing_sequence))
print('The smallest most frequent element in the sequence is: {}'.format(
smallest_most_frequent))

``````

Resource created Friday 14 August 2015, 03:19:54 PM, last modified Friday 14 August 2015, 03:20:09 PM.

file: quiz_1_sol.py