Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to make a car thing that tells you the current speed, max,speed, % of gas left etc. on spyder. It also needs to have 2-10 destinations on a GPS thing. I'm stuck on the GPS thing. By the way the GPS thing is aka destination.

What I have tried:

This is what I have so far:

<pre lang="Python">class Car(object):
    def __init__(self, max_speed, acceleration):
        self.max_speed = max_speed
        self.acceleration = acceleration
        self.current_speed = 0
        

    def speedup(self, time):
        self.current_speed = self.current_speed + self.acceleration * time
        if self.current_speed > self.max_speed:
            print ("Warning!!! The current speed is faster than the max. speed.")
            self.current_speed = self.max_speed
        return self.current_speed
    
    
    def speeddown(self, time):
        self.current_speed = self.current_speed / time
        return self.current_speed

    
    def distance(self, destination):
        distance = 0
        distance = distance + destination
        return self.distance
        

    def check_gas(self, time, current_speed):
        distance = time * current_speed
        gas = 500
        if distance == +1:
            gas - 1
        if gas == 50:
            print("Warning, low on gas.")
        return self.check_gas


lamborghini_asterion = Car(400, 40)
lamborghini_asterion.speedup(10)
lamborghini_asterion.speeddown(2)
    
old_barn = 1
#vancouver_airport = 53
#usa_border = 124
#sir_willam_osler_elementary_school = 12
#science_world = 34
#living_shangri_la = 25
print ("Please only type in lowercase!")
destination = input ("Choose from: Old barn 1km away | Vancouver Airport 53km away | USA Border 124km away | Sir William Osler Elementary School 12km away | Science World 34km away | Living Shangri-La 25km away: ")
if destination == ("old barn"):
     print ("You arrived in " + (old_barn / lamborghini_asterion.current_speed) + "minutes. You have " + (lamborghini_asterion.check_gas) + "gas out of 500 after you arrived")
Posted
Updated 12-Nov-17 9:20am
v3
Comments
Jingchun Su 12-Nov-17 0:55am    
Hello?
OriginalGriff 12-Nov-17 1:50am    
Hello!
Patrice T 12-Nov-17 2:10am    
Hello !
You know what . It is Sunday
CHill60 12-Nov-17 6:47am    
What is the "GPS thing"?
You are more likely to get help if you state your problem clearly.
Jingchun Su 12-Nov-17 15:42pm    
I changed the description I added what the gps thing is.

1 solution

I'm done now:
Python
import time
class Car():
    def __init__(self, max_speed, acceleration, total_gas):
        self.max_speed = max_speed 
        self.acceleration = acceleration
        self.total_gas = total_gas
        self.current_speed = 0
        self.distance = 0
        self.old_gas = total_gas
        

    def speedup(self, time):
        self.current_speed = self.current_speed + self.acceleration * time
        if self.current_speed >= self.max_speed:
            print ("Warning!!! The current speed is faster or the same as the max. speed.")
            self.current_speed = self.max_speed
        return self.current_speed
    
    
    def speeddown(self, time):
        self.current_speed = self.current_speed / time
        return self.current_speed


    def check_gas(self, distance):
         current_gas = self.old_gas - distance
         print ("You have " + str (current_gas) + " gas out of " + str (self.total_gas) + " after you arrived")
         self.old_gas = current_gas
         if current_gas <= 50 and current_gas > 0:
             print("Warning low on gas!!")
         if current_gas <= 0:
             print ("No more gas. 😢 ")
         return current_gas

class electronic_car(Car):
    def __init__(self, battery_life, max_speed, acceleration):
#        self.battery_life = battery_life
#        self.max_speed = max_speed
#        self.acceleration = acceleration
#        self.current_speed = 0       
#        self.old_battery = battery_life
        
        super().__init__(max_speed, acceleration,0)
        self.old_battery = battery_life
        self.battery_life = battery_life
    
    def check_gas(self):
        print("Gas is not available in electronic_car.")

  
    
def GPS ():
    lamborghini_asterion = Car(650, 40, 500)
    lamborghini_asterion.speedup(13)
    print ("Type exit to exit")
    print ("Please only type in lowercase!")
    print ("Type the numbers not the words!")
    while True:  
        old_barn = 1
        vancouver_airport = 41
        usa_border = 124
        sir_willam_osler_elementary_school = 12
        science_world = 32
        gas_station = 10
        destination = input (""" Choose from: 
        1: Old barn 1km away  
        2: Vancouver Airport 41km away 
        3: USA Border 124km away 
        4: Sir William Osler Elementary School 12km away 
        5: Science World 34km away 
        6: Gas station 10km away: """)
        if destination == ("exit"):
            break
        if destination == ("1"):
            oldbarn = old_barn /  lamborghini_asterion.current_speed
            print ("You are traveling at the speed of " +  str (lamborghini_asterion.current_speed) + (" km per hr"))
            time.sleep(1) 
            lamborghini_asterion.check_gas(1)
            print ("You arrived in " + str (oldbarn) + " hours.")
        if destination == ("2"):
            vancouverairport = vancouver_airport /  lamborghini_asterion.current_speed
            print ("You are traveling at the speed of " +  str (lamborghini_asterion.current_speed) + (" km per hr"))
            time.sleep(7) 
            lamborghini_asterion.check_gas(41)
            print ("You arrived in " + str (vancouverairport) + " hours.")
        if destination == ("3"):
            usaborder = usa_border /  lamborghini_asterion.current_speed
            print ("You are traveling at the speed of " +  str (lamborghini_asterion.current_speed) + (" km per hr"))
            time.sleep(12) 
            lamborghini_asterion.check_gas(124)
            print ("You arrived in " + str (usaborder) + " hours.")
        if destination == ("4"):
            sirwillamoslerelementaryschool = sir_willam_osler_elementary_school /  lamborghini_asterion.current_speed
            print ("You are traveling at the speed of " +  str (lamborghini_asterion.current_speed) + (" km per hr"))
            time.sleep(4) 
            lamborghini_asterion.check_gas(12)
            print ("You arrived in " + str (sirwillamoslerelementaryschool) + " hours.")
        if destination == ("5"):
            scienceworld = science_world /  lamborghini_asterion.current_speed
            print ("You are traveling at the speed of " +  str (lamborghini_asterion.current_speed) + (" km per hr"))
            time.sleep(6) 
            lamborghini_asterion.check_gas(32)
            print ("You arrived in " + str (scienceworld) + " hours.")
        if destination == ("6"):
            gasstation = gas_station /  lamborghini_asterion.current_speed
            print ("You are traveling at the speed of " +  str (lamborghini_asterion.current_speed) + (" km per hr"))
            time.sleep(5) 
            lamborghini_asterion.check_gas(10)
            print ("You arrived in " + str (gasstation) + " hours.")
            lamborghini_asterion.old_gas=lamborghini_asterion.total_gas
            lamborghini_asterion.current_gas = lamborghini_asterion.total_gas
            print ("You refilled you gas tank to 500")
 
Share this answer
 
Comments
PIEBALDconsult 18-Nov-17 21:54pm    
Please don't answer your own question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900