Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python 3.4 MyProgramming Lab It needs to be as simple as possible. Each question

ID: 673891 • Letter: P

Question

Python 3.4

MyProgramming Lab

It needs to be as simple as possible. Each question is slightly different.

1. The factors of an integer are those numbers that evenly divide into the integer. Given the integer n, create a list of all the factors of n, excluding 1 and n itself. The list should be ordered from smallest to largest. Associate the new list with the variable factors.

2. The factors of an integer are those numbers that evenly divide into the integer. Given the integer n, create a list of all the factors of n, excluding 1 and n itself. Associate the new list with the variable factors. The list should be ordered from largest to smallest.

3.

Given the list lst of positive integers, associate the largest duplicated element with the variable max_dup. If the list contains no duplicates, associate -1 with max_dup

Explanation / Answer

#1.
n = 24
factors = []

factor = 1

while(factor<= n):
if n%factor == 0:
factors.append(factor)
factor = factor+1

print factors

#2.

n = 24
factors = []

factor = n

while(factor>=1):
if n%factor == 0:
factors.append(factor)
factor = factor-1

print factors

#3.
positive_integers = [1,1,2,3,4,5,8,8,9,9]
max_dup = -1

for i in range(0,len(positive_integers)):
if positive_integers[i] in positive_integers[i+1:]:
max_dup = positive_integers[i]

print max_dup