Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Created March 11, 2021 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitaficionado/57b4d21b826f165c4312118ac23da3a3 to your computer and use it in GitHub Desktop.
Save gitaficionado/57b4d21b826f165c4312118ac23da3a3 to your computer and use it in GitHub Desktop.
Create a new program in Repl.it called "Lists." Your goal for this program is to create sections of code that will perform different outputs with the list called, names which contains the following values - Peter, Bruce, Steve, Tony, Natasha, Clint, Wanda, Hope, Danny, Carol and the list called numbers which contains the following values - 100, …
'''
Create a new program in Repl.it called "Lists." Your goal for this program is to create sections of code that will perform different
outputs with the list called, names which contains the following values - Peter, Bruce, Steve, Tony, Natasha, Clint, Wanda, Hope,
Danny, Carol and the list called numbers which contains the following values - 100, 50, 10, 1, 2, 7, 11, 17, 53, -8, -4, -9, -72, -64,
-80. At the beginning of your program, add in any comments and create the two lists. Then create the following:
A loop that will output every other name in the names list.
A loop that will output only the positive numbers in the numbers list.
A loop that will output the sum of all the values in the numbers list.
A loop that will output only the numbers that are odd.
A loop that will output only the names that come before "Thor" in the alphabet from the names list.
A loop that will find the maximum or minimum value in the numbers list. This algorithm requires an additional variable that is assigned to the first element in the list. Then, in a loop compare each element to the variable. If the element is > (for max) or < (for min), assign the variable to the element. After the loop, print the variable.
'''
# Lists
names = ["Peter", "Bruce", "Steve", "Tony", "Natasha", "Clint", "Wanda", "Hope", "Danny", "Carol"]
numbers = [100, 50, 10, 1, 2, 7, 11, 17, 53, -8, -4, -9, -72, -64, -80]
# Program 1
for n in names:
if names.index(n) % 2 == 0:
print(n)
# Alternate solution to Program 1
index = 0
for n in ______:
if index % ___ == 0:
print(___)
index = ______ + 1
# Program 2
for _____ in numbers:
if ____ >= 0:
print(____)
# Program 3
_______ = 0
for value in numbers:
total = _____ + total
print(____)
# Program 4
for _______ in numbers:
if number % ___ == 1:
print(_______)
# Program 5
for ______ in _____:
if name < "Thor":
print(_____)
# Program 6
# Find minimum value
min = numbers[__]
for ______ in numbers:
if ___ < min:
min = ___
print(min)
# Find maximum value
max = numbers[0]
for num in _________:
if num > max:
max = num
print(_____)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment