I was wondering if any of you guys could take a look at this. Just to kinda grade it and possibly see where I could make things simpler. From what I understand, part of coding is just trying to limit the amount of unnecessary tests, and just optimize things for a better look.

I've learned to keep tabs on errors; just for precautions I have areas labeled so I am 100% sure of where the coding lands. You can see that where I have print('Ticket'), print('A1'), and so on.

- Code: Select all
`from random import choice`

import time

Destination = 436480 # 248 miles

MDestination = 248

MTotal = 0

Ticket = 0

ALimit = 123200 # 70 miles

ASLimit = 70

AThres = 140800 # 80 miles

ASThres = 80

BLimit = 305600 # 60 miles

BSLimit = 60

BThres = 323200 # 70 miles

BSThres = 70

Speed = range(40, 91) # 1 yd to 1 mph = 1760

Distance = 0

while Distance < Destination:

MD = MDestination - MTotal # This is so driver doesn't go over the destination limit

Velocity = choice(Speed)

if MD <= 90:

if MD >=40:

Speed = range(40, MD+1)

Velocity = choice(Speed)

print('MD Test 1')

elif MD < 40:

Velocity = 40 - MD

Velocity = 40 - Velocity

print('MD Test 2')

MTotal = MTotal + Velocity

print('Velocity: ' + str(Velocity))

Distance = Distance + (Velocity * 1760)

print('Distance: ' + str(Distance))

if Distance < BLimit:

if Distance >= ALimit and Distance <= AThres:

if Velocity >= ASLimit+5 and Velocity < ASLimit+7:

n = range(1, 5)

Probability = choice(n)

if Probability == 2:

print('Ticket')

Ticket = Ticket + 1

print('A1')

elif Velocity >= ASLimit+7 and Velocity < ASThres+5:

n = range(1, 3)

Probability = choice(n)

if Probability == 1:

print('Ticket')

Ticket = Ticket + 1

print('A2')

elif Velocity >= ASThres+5:

print('Ticket')

Ticket = Ticket + 1

print('A3')

else:

if Distance >= BLimit and Distance <= BThres:

if Velocity >=BSLimit+5 and Velocity < ASLimit+7:

n = range (1, 5)

Probability = choice(n)

if Probability == 2:

print('Ticket')

Ticket = Ticket + 1

print('B1')

elif Velocity >= ASLimit+7 and Velocity < BSThres+5:

n = range(1, 3)

Probability = choice(n)

if Probability == 1:

print('Ticket')

Ticket = Ticket + 1

print('B2')

elif Velocity >= BSThres+5:

print('Ticket')

Ticket = Ticket + 1

print('B3')

print('You have ' + str(Ticket) + ' Tickets')

if Distance < Destination:

Final = Destination - Distance

Final = int(Final/1760)

print('You have only ' + str(Final) + ' miles to go.')