Question

__#define list of numbers numbersList = [4, 12, 35, 13, 8, 13, 0, 2, 13, 13,...

__#define list of numbers

numbersList = [4, 12, 35, 13, 8, 13, 0, 2, 13, 13, 56]

def removeUnlucky():

print("Unlucky: ",numbersList

)removeUnlucky(numbersList

)print("Lucky: ", numbersList)

Complete the function removeUnlucky(). the program will not run because the function is incomplete. remove every instance of the number 13 from the list. output is:

Unlucky: [4, 12, 35, 13, 8, 13, 0, 2, 13, 13, 56]
Lucky: [4, 12, 35, 8, 0, 2, 56]

Homework Answers

Answer #1

numbersList = [4, 12, 35, 13, 8, 13, 0, 2, 13, 13, 56]


def removeUnlucky(lst):
    i = 0
    while i < len(lst):
        if lst[i] == 13:
            lst.pop(i)
            i -= 1
        i += 1


print("Unlucky: ", numbersList)
removeUnlucky(numbersList)
print("Lucky: ", numbersList)


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
#define number of stars numStars = 6 #define function - takes a number of stars and...
#define number of stars numStars = 6 #define function - takes a number of stars and prints an upside-down triangle def printTriangle(): printTriangle(numStars) Complete the function printTriangle(). the function is incomplete. print a triangle of stars. output is: ****** ***** **** *** ** * __________________________ #define list of numbers numbersList = [4, 12, 35, 13, 8, 13, 0, 2, 13, 13, 56] def removeUnlucky(): print("Unlucky: ",numbersList )removeUnlucky(numbersList )print("Lucky: ", numbersList) Complete the function removeUnlucky(). the program will not run because...
#Constructor def tree(label, branches=[]): for branch in branches: assert is_tree(branch) return [label] + list(branches) #Selectors def...
#Constructor def tree(label, branches=[]): for branch in branches: assert is_tree(branch) return [label] + list(branches) #Selectors def label(tree): return tree[0] def branches(tree): return tree[1:] def is_tree(tree): if type(tree) != list or len(tree) < 1: return false return True def is_leaf(tree): return not branches(tree) def print_tree(t, indent=0):    print(' ' * indent + str(label(t))) for b in branches(t): print_tree(b, indent + 1) Write a function that takes in a tree and doubles every value. It should return a new tree. You can...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
1) a) From the set {-8, -2/3, 5i, √(-9), √2, 0, 3+3i, -2.35, 7} i) List...
1) a) From the set {-8, -2/3, 5i, √(-9), √2, 0, 3+3i, -2.35, 7} i) List the set of Natural Numbers ii) List the set of Integers iii) List of the set of Rational Numbers vi) List the set of Real Numbers 2)Solve the following pairs of simultaneous equations 3x + y = 7 and 2x - 2y = 2 b) i) -30 ÷ -6 - (-12 + 8) – 4 x 3 = c)Calculate the simple interest earned if...
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci...
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, … The sequence Fn of Fibonacci numbers is defined by the recurrence relation: Fn = Fn-1 + Fn with seed values F1 = 1 F2 = 1 For more information on...
In mathematical terms, the sequence Fn of Fibonacci numbers is 0, 1, 1, 2, 3, 5,...
In mathematical terms, the sequence Fn of Fibonacci numbers is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …….. Write a function int fib(int n) that returns Fn. For example, if n = 0, then fib() should return 0, PROGRAM: C
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS = 5000 # generates a random n-queens board # representation: a list of length n the value at index i is # row that contains the ith queen; # exampe for 4-queens: [0,2,0,3] means that the queen in column 0 is # sitting in row 0, the queen in colum 1 is in row, the queen in column 2 # is in row 0,...
Q TB TC NB MB MC 0 $0 0 $0 - - 1 27 35 2...
Q TB TC NB MB MC 0 $0 0 $0 - - 1 27 35 2 65 10 3 85 30 4 51 14 5 60 8 6 5 20 The attached spreadsheet includes incomplete information on the total benefits, total costs, net benefits, marginal benefits, and marginal costs of producing different quantities of output for a generic company. First, fill in the empty cells in the attached spreadsheet. What is the marginal benefit of producing the second unit of...
A sequence is a list of numbers that are calculated based on a certain rule. For...
A sequence is a list of numbers that are calculated based on a certain rule. For instance, the progression described by the rule An = 2 ∗ n results in the numbers: 0 2 4 6 8 10 ··· 2 ∗ n. The sum of this sequence can be calculated as Sn = 0+2+4+6+8+10+···+2 ∗ n. Write a function that takes as input the number n and calculates the sum of the sequence up to the nth term (inclusive) for...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT