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...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features the design of a calculator program using pseudocode and a Python program that uses a list and functions with variable scope to add, subtract, multiply, and divide. Open the M4Lab1ii.py program in IDLE and save it as M4Lab1ii.py with your initials instead of ii. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and...
Consider the following sequence of numbers 8, 1, 11, 4, 2, 9, 10, 5, 3, 12,...
Consider the following sequence of numbers 8, 1, 11, 4, 2, 9, 10, 5, 3, 12, 6, 7 c) Sort the list using quick sort with the middle element as pivot. Show the state of the list after each call to the partition procedure. You are not required to write code for this question. You need to trace through the different sorting algorithms using the given list. Please could I get an answer to the above question through using 9...
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...
[Lab Task HTML/JAVASCRIPT] Please read 10 numbers that are list below, sort the numbers and then...
[Lab Task HTML/JAVASCRIPT] Please read 10 numbers that are list below, sort the numbers and then print those numbers. 10 numbers = { 9, 3, 2, 1, 10, 30, 4, 6, 7, 8} Output should have a sorted list [Reference JavaScript code] <html> <body>     <H1>prompt()</h1>     <p id="pro"></p>     <script>        // Array creation        var num= new Array();               var ix = 0;        // Read 10 numbers        for (ix = 0; ix < 10; ix++)...
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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT