Question

In: Computer Science

"PYTHON" Declare a list that is initialized with six of your favorite sports teams. Print out...

"PYTHON"

Declare a list that is initialized with six of your favorite sports teams. Print out the number of teams to the shell. Use a for loop to print out the teams to the shell.

2. a. Declare a sporting goods list, initially with no elements.
b. Use a while loop to prompt the user for a sporting goods item and append the item to the list.
c. Break out of the loop when the user enters exit; do NOT append the word exit to the list.
d. Write a for s in sport_list loop to print out the elements in the list to the shell.
(BONUS) Add code to handle a ctrl-c exit.

3. a. Create a pressure list which initially contains no elements. b. Using the SenseHat, take 25 pressure measurements and store each measurement as a floating-point number in the list. Be sure to have the program sleep for a second or two between each measurement.
c. After recording the measurements, calculate the average of the pressure measurements- use the sum function and display the average on the SenseHat.

4. Allow the user to enter new sporting goods items at a specific index in the sporting goods list. Prompt the user for the index and the new item’s name.

5. Sort the sporting goods list in ascending order. Use a while loop to print out each item in the sporting goods list.

---Allow the user to delete an item from the sporting goods list. Prompt the user for the item’s name.

-- Sort the sporting goods list in descending order. Use a while loop to print out each item in the sporting goods list.


---a. Create a week_tuple and assign the days of the week as strings to the week_tuple.

b. Print out the elements in the week_tuple.

---a. The following list has been declared as follows:
credit_list = [24,3,15]

b. Convert the credit_list to a tuple named credit_tuple.

c. Print out the elements in the credit_tuple.

---a. Write an initialize_list_values function that takes in a number for the number of elements in a list and an initial value for each element. The function creates a new list and appends the elements with the initial value to the new list.

b. Pass in 5 and 3.4 as arguments to the intital_list_values and store the returned list in data_list.

c. Use a loop to print the elements of the data_list.

---a. Create a tuple named inventory_items_tuple which has Raspberry Pi 3, Raspberry Pi 2, and Raspberry Pi Camera Module.

b. Create a tuple named out_of_stock_items_tuple which has Raspberry Pi Zero. (Hint: add a , after “Raspberry Pi Zero”.)

c. Append these two tuples together into the all_items_tuple. Print out each element in the tuple using a for loop and use the len function to determine the number of elements in the tuple.
  

--a. Create a list of lists consisting of three rows and four columns, which were initially set to 0.
b. Prompt the user to initialize each element in the list of lists.
c. Compute the sum of all of the elements in the list. You may use the sum function.
d. Prompt the user to enter a row number and use a loop to calculate the sum of the elements in the row and print out the sum.

Solutions

Expert Solution

Solution:

Given data:

1)

teams = ["Denver Broncos","Atlanta Braves","Baltimore Ravens","Los Angeles Lakers","Dallas Cowboys","Atlanta Falcons"];
print('The list of sports team is:');
for i in range(0,6): #since we know that there are 6 teams, we can have a range from 0 to 6, where the indices will go from 0 to 6-1
    print(teams[i]); # print each team name

CODE:

OUTPUT:

2)

sport_list = []; #Declare a sporting goods list, initially with no elements
item = input('Enter a sporting good: '); #Read the first sporting item
while item.lower()!="exit": # until exit is entered, we need to continue with the loop
    #also item name is converted to lowercase so that exit written in any case can be handled
    sport_list.append(item); #append the item to list
    item = input('Enter a sporting good: '); #list the next item
print('The sporting goods list is: ');
for s in sport_list: #using for loop
    print(s); #print each item in the sport_list   


CODE:

OUTPUT:

3)

from sense_hat import SenseHat
from time import sleep

pressure = []; #Create a pressure list which initially contains no elements.
i = 0; # no of pressure values read is initialized to 0
sense = SenseHat(); #create a senseHat variable

while i < 25: # the loop goes on for 25 iterations
    p = sense.get_pressure(); #get the pressure
    pressure.append(sense); #append pressure to the list
    sleep(1); # sleep for 1 second
    i = i+1; #increment the count of pressure values read
  
sumval = sum(pressure); #sum up the pressures using the sum function
avg = sumval/25; #find the average

print('Average pressure = ', avg); #display average


CODE:

4)

sport_list = ["Bottles","Shoes","Protein"]; #Declare a sporting goods list
item = input('Enter a sporting good: '); #Read the sporting item
pos = int(input('Enter the index for new item: ')); #read the position for new item
sport_list.insert(pos,item); #insert item at given index
print(sport_list); #display the sport_list
          


CODE:

OUTPUT:

5)

sport_list = ["Bottles","Shoes","Protein","Belt","First Aid Kit","Cap"]; #Declare a sporting goods list
print('Original List: ',sport_list); #display original list
sport_list.sort()#sort the list by default in acending order
print('Sorted List (Ascending Order):');
i = 0; #iterator
while i < len(sport_list): #wehile i is less than length of list
    print(sport_list[i]); #print the list value
    i = i+1; #increment the iterator


CODE:

OUTPUT:

6)

sport_list = ["Bottles","Shoes","Protein","Belt","First Aid Kit","Cap"]; #Declare a sporting goods list
print('Original List: ',sport_list); #display original list
item = input('Enter the item to be deleted: ');
if item in sport_list: #if item is present in the list
    sport_list.remove(item); #remove the item
    print(item,'deleted successfully');
    print(sport_list); #display the updated list
else:
    print(item, 'not present in list'); #else, print item is not in the list


CODE:

OUTPUT:

7)

sport_list = ["Bottles","Shoes","Protein","Belt","First Aid Kit","Cap"]; #Declare a sporting goods list
print('Original List: ',sport_list); #display original list
sport_list.sort(reverse=True)#sort the list in descending order
print('Sorted List (Descending Order):');
i = 0; #iterator
while i < len(sport_list): #wehile i is less than length of list
    print(sport_list[i]); #print the list value
    i = i+1; #increment the iterator

CODE:

OUTPUT:

PLEASE GIVEME THUMB UP.........


Related Solutions

2) create a python program that uses a for loop and range to print out the...
2) create a python program that uses a for loop and range to print out the values 10 8 6 4 2 3) Create a python program that yses a for loop to print out ["bob","al","bert"]
11. Print the length of the new list out to the screen. Ensure the new list...
11. Print the length of the new list out to the screen. Ensure the new list has a length of 25. 12. Append the integer value 42 to the new list. Print the new list to the screen.   13. Permanently sort the new list. Print the new list to the screen. 14. Remove the integer value 42 from the new list. Print the new list to the screen. 15. Implement a for loop to iterate through the new list. For...
Python create a function tryhard and print out the dictionary as a string form. For example...
Python create a function tryhard and print out the dictionary as a string form. For example def tryhard(d:dict): #Code here input: d = {'first': {}, 'second': {'1': {'move'}, '0': {'move', 'slow'}}, 'third': {'1': {'stop'}}} output = " first movie: [ ]\n third movie: [('1', ['stop'])]\n second movie: [('0', ['slow', 'move']), ('1', ['move'])]\n"
In this assignment you will create a web page about your favorite sports to play or...
In this assignment you will create a web page about your favorite sports to play or teams to watch. If you don’t watch or play sports, please make up your favorite sports to play or teams to watch. You will be incorporating images into your web page, as well as other concepts learned in this unit. Create an external style sheet using a text editor of your choosing. In the CSS file add the following style rules: A background image...
Suppose you are planning on becoming a vendor at the arena where your favorite sports team...
Suppose you are planning on becoming a vendor at the arena where your favorite sports team plays. You are trying to decide between opening up a souvenir stand selling T-shirts, caps, etc., with your sports team’s logo or opening up a hot dog and beer stand. It is more expensive to open up the hot dog and beer stand because you need to purchase a license to serve alcohol and you need to spend money to comply with health department...
a) Design an E-R diagram for keeping track of the scoring statistics of your favorite sports...
a) Design an E-R diagram for keeping track of the scoring statistics of your favorite sports team. You should store the matches played, the scores in each match, the players in each match, and individual player scoring statistics for each match. Summary statistics should be modeled as derived attributes with an explanation as to how they are computed. b) Construct appropriate relation schemas for the E-R diagram (ex. customer(name, ID, birth))
(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
#python #code #AP class #Tech write a function code script which will print out number pyramid...
#python #code #AP class #Tech write a function code script which will print out number pyramid in the form of * so the output will be made up of **** resting on top of each other to form a pyramid shape. Bottom layer should be made of 5 multiplication signs like ***** then next 4 multiplication signs and so on. Top part should have only one *
List your favorite retail company. Does this company participate in globalization? List two methods this company...
List your favorite retail company. Does this company participate in globalization? List two methods this company can use to improve and customer service.
For Python, I cannot figure out why "and" is printing at the beginning of my list....
For Python, I cannot figure out why "and" is printing at the beginning of my list. Can someone help? listToPrint = [] while True: newWord = input("Enter a word to add to the list (prest return to stop adding words) > ") newWord == "": break else: listToPrint.append(newWord) for item in listToPrint[:-1]: print(item, end=', ') print('and', listToPrint[-1]) If I enter m, n, b to the list, it executes to and m, n, b
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT