Question

In: Computer Science

This is an exercise on basic python grammar. Instructions Assume there are 10 teams in a...

This is an exercise on basic python grammar.

Instructions

Assume there are 10 teams in a competition. Their names are "team1", "team2" .. "team10".

Write a function to generate their order of performance randomly.

Submit your code in Jupyter notebook format (.ipynb) on Canvas

Hint

  1. Use a list to save all the team names
  2. Define a function called order()  
  3. Use built-in module random to generate a random index within the list
  4. Remove the item from the current list and add it to a new empty list
  5. Repeat this until the old list is empty (length of the list becomes 0)

Note: You may certainly use another data structure or another algorithm without following the above suggested steps.

Solutions

Expert Solution

Solution:

Look at the code and comments for better understanding............

Screenshot of the code and output in Jupyter Notebook:

Code to copy:

import random
def order(teams):
    new_list = []
    #find the length of the list 
    l = len(teams)
    #loop untill the length becomes zero
    while l!=0:
        #generate a random index in the range 0 to l-1
        index = random.randint(0,l-1)
        #add the element at index to the new list
        new_list.append(teams[index])
        #remove the element at index from old list
        teams.pop(index)
        #decrement the length
        l-=1
    #return the new list
    return new_list

teams = ['team1','team2','team3','team4','team5','team6','team7','team8','team9','team10']
print(order(teams))

I hope this would help...................:-))


Related Solutions

Instructions In this exercise, you will use Python to complete four practical challenges: Creating 24 directories...
Instructions In this exercise, you will use Python to complete four practical challenges: Creating 24 directories for each week of class, each containing 3 folders for each day of class Copying files from ~/Downloads into the current directory Adding the copy script to the PATH Add an alias for the copy script to ~/.bashrc Class Notes Folder Create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called...
Python Exercise 2 A program is to display all odd numbers between 10 and 3000. The...
Python Exercise 2 A program is to display all odd numbers between 10 and 3000. The starting value and end value are to be assigned by the programmer, not requested from user.
The programming language is Python Instructions: Create a function that will delete a node in a...
The programming language is Python Instructions: Create a function that will delete a node in a Linked List based on position number. On below example, if you want to delete position #2, it will remove the Banana (arrangement of nodes below is Apple, Banana, Cherry, Grapes, Orange). myLinkedList = LinkedList() myLinkedList.append("Banana") myLinkedList.append("Cherry") myLinkedList.append("Grapes") myLinkedList.append("Orange") myLinkedList.prepend("Apple") myLinkedList.deleteByPositionNum(2) node = myLinkedList.head while node: print(node.value, " ") node = node.next_node You may start with the function head: def deleteByPositionNum(self, positionNum):
Exercise 10-22 The following transactions occurred during 2020. Assume that depreciation of 10% per year is...
Exercise 10-22 The following transactions occurred during 2020. Assume that depreciation of 10% per year is charged on all machinery and 5% per year on buildings, on a straight-line basis, with no estimated salvage value. Depreciation is charged for a full year on all fixed assets acquired during the year, and no depreciation is charged on fixed assets disposed of during the year. Jan. 30 A building that cost $190,080 in 2003 is torn down to make room for a...
Exercise 10-22 The following transactions occurred during 2017. Assume that depreciation of 10% per year is...
Exercise 10-22 The following transactions occurred during 2017. Assume that depreciation of 10% per year is charged on all machinery and 5% per year on buildings, on a straight-line basis, with no estimated salvage value. Depreciation is charged for a full year on all fixed assets acquired during the year, and no depreciation is charged on fixed assets disposed of during the year. Jan. 30 A building that cost $179,520 in 2000 is torn down to make room for a...
Exercise 10-22 The following transactions occurred during 2017. Assume that depreciation of 10% per year is...
Exercise 10-22 The following transactions occurred during 2017. Assume that depreciation of 10% per year is charged on all machinery and 5% per year on buildings, on a straight-line basis, with no estimated salvage value. Depreciation is charged for a full year on all fixed assets acquired during the year, and no depreciation is charged on fixed assets disposed of during the year. Jan. 30 A building that cost $179,520 in 2000 is torn down to make room for a...
Five sophomores were given an English achievement test before and after receiving instruction in basic grammar....
Five sophomores were given an English achievement test before and after receiving instruction in basic grammar. The mean difference score is -0.40, and the estimated variance for the difference scores is 8.3. Using the .05 significance level (and five steps of hypothesis testing) is it reasonable to conclude that future students would show higher scores after instruction? Step I: -Population 1: -Population 2: - Research hypothesis: Null hypothesis: Step II: Give the characteristics of the comparison distribution -The shape is:...
PYTHON Exercise: Accelerate Method ------------------------- ### Description In this exercise, you will add to your `Car`...
PYTHON Exercise: Accelerate Method ------------------------- ### Description In this exercise, you will add to your `Car` class a method to accelerate the speed of an instance. ### Class Name `Car` ### Method `accelerate()` ### Parameters * `self` : the `Car` object to use * `delta_speed` : a number, the desired value to add to the speed data member. ### Action Adds `delta_speed` to the speed of the object. If the new speed is too fast, then set the speed to...
4.9 Branching Practice - Python Exercise #Write the code for the following # Exercise 1 #...
4.9 Branching Practice - Python Exercise #Write the code for the following # Exercise 1 # Ask user for a number using an input statement (no prompt) & assign the input to a variable # Convert the user entry to an integer and assign it to a variable # Condition: user entry is greater than zero # Action: display the following word on screen: positive # Exercise 2 # Ask user for a number using an input statement (no prompt)...
USE BASIC PYTHON Focus on Basic file operations, exception handling. Save a copy of the file...
USE BASIC PYTHON Focus on Basic file operations, exception handling. Save a copy of the file module6data.txt (Below) Write a program that will a. Open the file module6data.txt b. Create a second file named processed. txt c. Read the numbers from the first file one at a time. For each number write into second file, if possible, its I. Square ii. Square root iii. Reciprocal (1/number)use a math module function for the square root. use exception handling to trap possible...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT