Skip to content
Sign upLog in
← Back to Community


Profile icon

names = []

value1 = 0
value2= 0
def compare() :
if value1 > value2 :
print("Value1 is greater than Value2.")
elif value2 > value1 :
print("Value2 is greater than Value1.")
elif value1 == value2 :
print("Value 1 and Value 2 are equal.")
#Add the beginning comments at the top of the program.
#In the first part of your program, create a for loop that runs three times:
#Inside the for loop, prompt the user for an integer
#Prompt the user for another integer
#Call the function compare (you are going to create this function next)
#Pass the variables that you used for the integer inputs from above
index = 0
while index <= 3 :
value1 = int(input("\nPick a number."))
value2 = int(input("Pick another number."))
index = 1 + int(index)
#Create a function called compare (remember the function definition should go at the top of the program) and use two variables in the parameters of the function:
#Inside of the function, create an if / elif / else structure that compares the two values passed into the function
#If one value is less than the other, output that to the user (Ex: 2 is less than 4)
#Elif the other value is less than the other output something similar (Ex: 4 is less than 9)
#Else, output that they are equal to each other
#That is it for the first part of the program.

#All things above were for the first program with the compare function.

#All things below are for the name list with the eliminate function.

#Next, create an empty list called names.

#Create a loop that runs 6 times:
import random
def eliminate():
while len(names) > 1:
print("\nThe original list : " + str(names))
print("List after removal of random number : " + str(names))
print("/nThe last remaining member is" + str(names))
#Inside of the for loop, prompt the user for a name
#Append the name to the list
index = 0
names = []
while index < 6 :
names.append(input("\nPlease add a name."))
index = 1 + int(index)

#Outside of the for loop, prompt the user for how many people they would like to vote off the island.
#Call the function eliminate and pass the variable you used from step 7 to it.
#Also, this function will return a value, so store this back function call back to a new variable.
#Create a function called eliminate and create a variable to use as the parameter:
#Inside the function, randomly shuffle (use the shuffle() method) all the values in the list (you will need to import random at the top of the program)
#Then using a for loop, loop it as many times as the value that was passed to the function:
#Inside the for loop, remove one name from the list (use the pop() method)
#Outside the for loop, but still inside the function, return the list of remaining people
#Underneath where you left off in step 8, print the remaining people that are left: those that did not get voted off the island

#credit to

Profile icon
Profile icon