2016-07-31 284 views
-4

嗨,即時通訊目前堅持這一挑戰,我試圖解決它的一天了,我可能是愚蠢的,因爲它的東西很簡單,但即時在字面上腦死了,太累了花了太多時間試圖弄清楚這樣的IM要去尋求幫助,看是否有人能解決這個問題,感謝您的幫助:)挑選挑戰4:蟒蛇挑戰

I had to take a screen shot hope you can read it. If anyone manages to solve it can you explain to me or give me the code although i prefer for the explination so that i undersstand it for later thanks. CLICK FOR THE PICTURE

這是我在它的企圖,這是我所有的代碼不工作:(

station1 = int(input("Enter the number of stations: ")) 
adult = int(input("How many adults will be with you: ")) 
child = int(input("How many children will be with you: ")) 
time = int(input("And what is the time you wish to travel (24 hour clock): ")) 


station2 = station1 * 20 


if station2 > 0: 
    print ("Current fair is: ", station2) 
    if child > 0: 
     station2 = station2/2 
     print ("Because of children its half price: ", station2) 
    elif time == 6: 
     station2 * 5 
     print (station2) 
    elif time == 7: 
     station2 * 5 
     print (station2) 
    elif time == 8: 
     station2 * 5 
     print (station2) 
    elif time == 9: 
     station2 * 5 
     print (station2) 
    else: 
     print (station2) 
else: 
    print ("you need at least one station") 
+3

你介意說明你的代碼的實際問題是什麼? 「它不工作」意味着我們必須找出問題並解決問題。 – Aurora0001

+0

那麼我的代碼的問題是,它不會輸出所需的輸出需要顯示在上面的屏幕截圖 – OkamiBushi

回答

0

也許我們錯過了一些數據:假設乘火車從一個站到另一個站需要多少錢?

設置它將採用timedelta有多長(分鐘= X):

# calculate price 
# 20 per stations 
# 1/2 children 
# +5 per stations from 6 to 9 
import datetime 
def calc_price(stations, adults, children, start_hour): 
    time = datetime.datetime.today().replace(hour=start_hour, minute=0, second=0, microsecond=0) 
    price = 0.0 
    for x in range(stations): 
     if 6 <= time.hour <= 9: 
      price += 5 

     price += 20 
     time += datetime.timedelta(minutes=15) 

    # adults = adults-children 
    result = price * (adults + children/2.0) 

    return result 


def test_examples(): 
    assert calc_price(2, 1, 0, 10) == 40 
    # assert calc_price(4, 2, 2, 11) == 120 
    assert calc_price(2, 1, 0, 8) == 50 
    assert calc_price(4, 1, 0, 8) == 100 
    assert calc_price(3, 1, 1, 7) == 112.50 
    assert calc_price(0, 0, 0, 0) == 0 


if __name__ == '__main__': 
    test_examples() 

但是這個數據了幾個測試失敗。

+0

好吧,從我猜測我不認爲所有的答案都應該是正確的我想,但感謝您的幫助即時通訊只是做我認爲是正確的,看看會發生什麼:) – OkamiBushi

0

一時間,如果不考慮額外的車費在特定的時間間隔,總費用可以計算爲:

total=(Station1*min(adult,1)*20) + (Station1*min(child,1)*10) 

現在,所有你需要做的是包括邏輯語句來檢查是否'時間'屬於額外收費的時間間隔,並相應地調整您的總額。

+0

感謝您的幫助:) – OkamiBushi