Question

Question 30 What is output? my_list = [20.0, 6, 11, 3, 90, 3.3] my_list.sort first = 0 last - len(my_list) - 1 count = 0 num_
0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Creation of list
my_list = [20.0, 6, 11, 3, 90, 3.3]
# Sorting of list
my_list.sort()

# intialization of first and last variable with the list index
first = 0
last = len(my_list) -1

# initialization of count variable to 0
count = 0
# intialization of number to be found out
num_to_find = 100//5


while last >=  first: # checking if we finished the list
    mid = (first + last) // 2 # finding the midpoint
    count += 1 # incrementing the count variable
    # if the mid value is lesser than the number to be found, changing the first value to change list
    if my_list[mid] < num_to_find:
        first = mid + 1
    # if the mid value is greater than the number to be found, changing the last value to change list
    elif my_list[mid] > num_to_find:
        last = mid + 1
    # if the mid value is equal to the number, we print the index and the iterations it took
    else:
        print(mid, count)
        break

The answer is

4 2

Add a comment
Know the answer?
Add Answer to:
Question 30 What is output? my_list = [20.0, 6, 11, 3, 90, 3.3] my_list.sort first =...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Show that mergesort is a stable algorithm by modifiying the algorithm to sort a list of tuples (first and last names) by...

    Show that mergesort is a stable algorithm by modifiying the algorithm to sort a list of tuples (first and last names) by their second position. (Modify the merge section to break ties) Modify in python def mergesort(mlist): if len(mlist) < 2: return mlist else: mid = len(mlist)//2 return merge( mergesort(mlist[:mid]), mergesort(mlist[mid:])) # merge two sorted lists def merge(left, right): if left == []: return right elif right == []: return left elif left[0] < right[0]: return [left[0]] + merge(left[1:], right)...

  • Show that mergesort is a stable algorithm by modifiying the algorithm to sort a list of...

    Show that mergesort is a stable algorithm by modifiying the algorithm to sort a list of tuples (first and last names) by their second position. (Modify the merge section to break ties) Modify in python def mergesort(mlist): if len(mlist) < 2: return mlist else: mid = len(mlist)//2 return merge( mergesort(mlist[:mid]), mergesort(mlist[mid:])) # merge two sorted lists def merge(left, right): if left == []: return right elif right == []: return left elif left[0] < right[0]: return [left[0]] + merge(left[1:], right)...

  • Question 17 (3 points) Predict the output of the following code segment: a = 99.98 if...

    Question 17 (3 points) Predict the output of the following code segment: a = 99.98 if a + 0.01 >= 100: print('A') elif a + 0.02 >= 100: print('B') print('c') else: print('D') print('E') Question 16 (3 points) Predict the output of the following code segment: X = 6 if x % 2 == 0: print ("x is even.") else: print ("x is odd.") Please use the decimal point to distinguish int and float. For example, number 3 + number 4...

  • (In Python 3) Write a program with total change amount as an integer input, and output...

    (In Python 3) Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes So...

  • Convert this code written in Python into Java: valid = False; while(valid == False):    username...

    Convert this code written in Python into Java: valid = False; while(valid == False):    username = input ("Please enter a username:")    length = len(username);    if(length < 8 or length > 15):        print("Username must be between 8 and 15 characters.")    else:               if(username.isalnum() == False):            print("Username must contain only alphanumeric characters.");        else:            count = 0;            inx = 0;           ...

  • 1,4,5 Multiple Choice (Find Output or Fix Error) 1. What will be the final value of...

    1,4,5 Multiple Choice (Find Output or Fix Error) 1. What will be the final value of product 7、 inta,b; Given above code, what will be the value of a andb if user types: 31 42 nt producr- 3, product 3 prodct while (product70) a) 81 31 What is the output of the following code? char Grade8 27 8. d) Error in do-while code 2. This loop is a good choice when you know how many times you want the loop...

  • I'm making a To-Do list in Python 2 and had the program running before remembering that...

    I'm making a To-Do list in Python 2 and had the program running before remembering that my professor wants me to put everything in procedures. I can't seem to get it to work the way I have it now and I can't figure it out. I commented out the lines that was originally in the working program and added procedures to the top. I've attached a screenshot of the error & pasted the code below. 1 todo_list = [] 2...

  • In python this is what I have for task 3, but I don't know how to...

    In python this is what I have for task 3, but I don't know how to fix it so that the computer stops picking from the pile once it reaches zero Task 3: Extend the game to have two piles of coins, allow the players to specify which pile they take the coins from, as well as how many coins they take Finish Task 3 and try three test cases import random remaining_coins1 = 22 remaining_coins2 = 22 while 1:...

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that...

    Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that takes as input a list of numbers and returns a list of the first sequence within that is increasing order, and has a length of at least 2. If no increasing sequential numbers are found, (ie. the input list is in descending order) then naturally a list of just the first value is returned. Increasing sequence means for a number to be valid it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT