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

In python, why is it advantageous to store not just data (as vectors, arrays,etc.) but perhaps...
In python, why is it advantageous to store not just data (as vectors, arrays,etc.) but perhaps the object (an instance of your user-defined class) that contains and is able to manipulate these data in a data file through maybe the pickle module? Without importing your own class definition, will the data load from such a data file be usable or interpretable? Explain and write some codes to support your ideas if possible.
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...
Write a Python program that performs the following list operations. Part A Define a list called...
Write a Python program that performs the following list operations. Part A Define a list called numList with elements. 84, 94, 27, 74, 19, 90, 16, 21, 56, 50, 77, 59, 41, 63, 18, 26, 80, 74, 57, 30, 40, 93, 70, 28, 14, 11, 43,65, 91, 83, 22, 53, 74, 44, 73, 55, 47, 74, 81 Display the followings: All the numbers in numList The number of elements in numList The smallest number in numList The largest number in...
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
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT