Jingchun Su Ответов: 1

Как я могу сделать автомобильную вещь, которая говорит вам текущую скорость, процент газа и т. д. в Python


Я пытаюсь сделать автомобильную штуку, которая сообщает вам текущую скорость,Макс, скорость, % оставшегося газа и т. д. На spyder. Он также должен иметь 2-10 мест на GPS-навигатор. Я застрял на этой штуке с GPS. Кстати, эта штука с GPS-это тоже пункт назначения.

Что я уже пробовал:

Это то, что у меня есть до сих пор:

<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")

Jingchun Su

- Алло?

OriginalGriff

- Привет!

Patrice T

- Привет !
Ты знаешь что . Сегодня воскресенье

CHill60

Что такое "GPS-штука"?
Вы с большей вероятностью получите помощь, если четко сформулируете свою проблему.

Jingchun Su

Я изменил описание и добавил, что такое gps.

Jingchun Su

Похоже, мы находимся в разных часовых поясах.

Jingchun Su

Сейчас 11:30 утра.

Jingchun Su

Я изменил немного код

Jingchun Su

Эй, ребята, вы спите?

Jingchun Su

лол

Jingchun Su

@OriginalGriff где ты живешь?

Jingchun Su

кто голосовал против??

CHill60

ОГ живет в Великобритании.
Все часовые пояса покрываются членами клуба.
Ваш вопрос все еще неясен, что, вероятно, объясняет понижающий голос.
Вы не можете сказать, кто понизил голос.

Jingchun Su

Вы проголосовали против CHill60

CHill60

Нет, я этого не делал.

1 Ответов

Рейтинг:
1

Jingchun Su

С меня хватит:

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")


PIEBALDconsult

Пожалуйста, не отвечай на свой вопрос.