Question

In: Computer Science

Python programming Summary Store the times into arrays called Chevy[ ] and Ford[ ]. Then list...

Python programming Summary

Store the times into arrays called Chevy[ ] and Ford[ ]. Then list the winner of each pair, giving the number of seconds the winner won by. At the end declare which team won based on which team had the most wins.

Lab Steps

There are eight cars in each team called Chevy and Ford. One car from each team races its opponent on the drag strip. Read in the racing times for the eight Chevy cars and then read in the times for the eight Ford cars.

Sample Match:

---Input Chevy Times---
Enter time for Chevy Car 1: 5.4
Enter time for Chevy Car 2: 7.2
Enter time for Chevy Car 3: 4.0
Enter time for Chevy Car 4: 9.1
Enter time for Chevy Car 5: 5.8
Enter time for Chevy Car 6: 3.9
Enter time for Chevy Car 7: 6.2
Enter time for Chevy Car 8: 8.1
---Input Ford Times---
Enter time for Ford Car 1: 5.8
Enter time for Ford Car 2: 6.9
Enter time for Ford Car 3: 3.9
Enter time for Ford Car 4: 9.2
Enter time for Ford Car 5: 5.8
Enter time for Ford Car 6: 3.8
Enter time for Ford Car 7: 6.0
Enter time for Ford Car 8: 8.5
And the winners are:
Chevy by 0.4 sec
Ford by 0.3 sec
Ford by 0.1 sec
Chevy by 0.1 sec
Tie!
Ford by 0.1 sec
Ford by 0.2 sec
Chevy by 0.4 sec
And the winning team is: F O R D !

Specifications:

  • Accept the racing times for each of the Chevy cars into the array Chevy[ ].
  • Accept the racing times for each of the Ford cars into the array Ford[ ].
  • Then declare the wining car for each race, giving the winning time in seconds.
  • If the times are identical, then declare the race was a tie.
  • Finally, declare which team won the match, assuming a tie is possible.

Solutions

Expert Solution

Code:

chevy=[]
ford=[]
chevyCount=0 #count wins
fordCount=0
print("---Input Chevy times---")
for i in range(8):   
   print("Enter time for Chevy Car ",i+1,":",end='')
   a=float(input())
   chevy.append(a)
  
print("---Input Ford times---")
for i in range(8):
   print("Enter time for Ford Car ",i+1,":",end='')
   a=float(input())
   ford.append(a)

print("And the winners are:")

for i in range(8):
   if(chevy[i]>ford[i]):   
       print("Chevy by ",round(chevy[i]-ford[i],1)," sec") #difference time rounded to 1 decimal
       chevyCount=chevyCount+1
  
   elif(ford[i]>chevy[i]):
       print("Ford by ",round(ford[i]-chevy[i],1)," sec")
       fordCount=fordCount+1
  
   else:
       print("Tie!")
  
if(chevyCount>fordCount): #based on win counts
   print("And the winning team is F O R D !")

elif(fordCount>chevyCount):
   print("And the winning team is C H E V Y !")

else:
   print("T I E !")

Output:


Related Solutions

Arrays provide the programmer the ability to store a group of related variables in a list...
Arrays provide the programmer the ability to store a group of related variables in a list that can be accessed via an index. This is often very useful as most programs perform the same series of calculations on every element in the array. To create an array of 10 integers (with predefined values) the following code segment can be utilised: int valueList[10] = {4,7,1,36,23,67,61,887,12,53}; To step through the array the index '[n]' need to be updated. One method of stepping...
a summary explaining the basic understanding of the following programming concepts using a language of python:...
a summary explaining the basic understanding of the following programming concepts using a language of python: •Variables •Arithmetic and Logical operations •Sequential coding (Structured programming •Decision structure (If statements) •Repetition structure •Functions with some coding demos inside visual studio code python IDE which can be sent as screenshot. preferably a typed summary please which can be written into powerpoint pleaseeeee ???
In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
Build a simple list implementation that uses arrays to store the values. Create a class SimpleArrayList...
Build a simple list implementation that uses arrays to store the values. Create a class SimpleArrayList with a public constructor that initializes the list using a passed array of Object references. Assert that the passed array is not null. Next, implement: 1)Object get(int), which takes an int index and returns the Object at that index 2)void set(int, Object), which takes an int index and an object reference and sets that value at the index to the passed reference Both your...
Python programming problem! Suppose that there is a json file called data from the desktop. I...
Python programming problem! Suppose that there is a json file called data from the desktop. I want to print the value with the key of "year" and "country". Json file below: { "A":{ "year":11, "grade":A, "country":America}, "B":{ "year":18, "grade":C, "country":England}, "C":{ "year":19, "grade":B, "country":China},} I want a code that I can only replace the name of key from year to grade and the code could be work.
programming in python Design a program that initializes a list of 5 items to zero (use...
programming in python Design a program that initializes a list of 5 items to zero (use repetition operator). It then updates that list with a series of 5 random numbers. The program should find and display the following data: -The lowest number in the list - Average of the numbers stored in the list
Solve using PYTHON PROGRAMMING 9. Write a script that reads a file “ai_trends.txt”, into a list...
Solve using PYTHON PROGRAMMING 9. Write a script that reads a file “ai_trends.txt”, into a list of words, eliminates from the list of words the words in the file “stopwords_en.txt” and then a. Calculates the average occurrence of the words. Occurrence is the number of times a word is appearing in the text b. Calculates the longest word c. Calculates the average word length. This is based on the unique words: each word counts as one d. Create a bar...
Python Programming Revise the ChatBot program below. There needs to be one list and one dictionary...
Python Programming Revise the ChatBot program below. There needs to be one list and one dictionary for the ChatBot to use. Include a read/write function to the program so that the program can learn at least one thing and store the information in a text document. ChatBot program for revising: # Meet the chatbot Eve print('Hi there! Welcome to the ChatBot station. I am going to ask you a series of questions and all you have to do is answer!')...
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times,...
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times, each time using a different syntax to define the list. Write a while loop that prints the numbers from 1 to 10. Convert your previous loop into a for loop. Rewrite your for loop to only have one number in the range. Write a for loop to print out each item of your list of 10 numbers, all on the same line, separated by...
By using Python: a. Make a class called Book. The __init__() method for Book should store...
By using Python: a. Make a class called Book. The __init__() method for Book should store two attributes: a title and an author. Make a method called book_info() that prints these two pieces of information, and a method called book_available() that prints a message indicating that the book is available in the library. b. Create an instance called book1 from your class. Print the two attributes individually, and then call both methods. c. Create three different instances from the class,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT