Question
Hello. I was wondering if anyone can help me with my programming homework, which is about a racing game. I have finished coding the speed
Hello. I was wondering if anyone can help me with my programming homework, which is about a racing game. I have finished coding the speed of the cars and the lap time, but I have yet to figure out the rest. This consists of the standing (making a list from 1-10 and assigning it to the lap time to give the cars a position in the race), engine failure (engine fails withing the middle 2.5% of the min speed and the max speed), and changing the lap time list to where the cars with an engine failure are now -1). I added what I have for my code so far. If anyone could help that would be greatly appreciated. Thank
def main():
import random laps = eval(input("Numbers of laps to be covered in the race (>1):")) distance = eval(input("Distance for each lap (>=10 km):")) min_speed = eval(input("The minimum speed for each car (>40km/hr):")) max_speed = eval(input("The maximum speed for each car (>min_speed):")) cars = 10 car_speed_list = [] car_speed = [random.randint(min_speed, max_speed) for k in range(10)]
if min_speed>max_speed: print("Error! The maximum speed", max_speed, "smaller than the mimimum speed", min_speed) exit() print(" ")
mid_speed = (max_speed+min_speed)/2 allowed_speed = max_speed-min_speed minimum_failed_speed = mid_speed-(allowed_speed * 0.025) maximum_failed_speed = mid_speed+(allowed_speed * 0.025) print("You have set the speed range:", [min_speed, max_speed]) faliure = print("Engine faliure speed range defined", [minimum_failed_speed, maximum_failed_speed])
print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
for i in range (laps): print("After lap", i+1, ":")
car_speed = [random.uniform(min_speed, max_speed) for k in range(10)] if laps > 0: car_speed_list.clear() for b in range (10): car_speed_list.append(round(car_speed[b], 2)) print("Car speed:", car_speed_list) lap_int = 60 lap_time_list = [round(i/lap_int, 2) for i in car_speed_list] print("Total time used (minutes):", lap_time_list)
standings = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print("Standings:", standings) print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started