2017-04-26 151 views
-5

定義功能print_popcorn_time()與參數bag_ounces。如果bag_ounces小於3,則打印「太小」。如果大於10,則打印「太大」。否則,計算並打印6 * bag_ounces,然後加上「秒」。以換行符結束。例如輸出bag_ounces = 7功能分支

42 seconds.

對於這個程序我得到吸吮的錯誤:

"File "main.py", line 6 
elif bag_ounces = bag_ounces * 6" 
       ^
def print_popcorn_time(bag_ounces): 
    if bag_ounces < 3: 
     print("Too small") 
    elif bag_ounces > 10: 
     print("Tool large") 
    elif bag_ounces = bag_ounces * 6 
    else: 
     print(bag_ounces) 

print_popcorn_time(7) 
+4

'='用於分配。你想'=='比較。 – Carcigenicate

+1

雖然我不認爲他想比較。 – Kevin

+0

什麼是錯誤? –

回答

1

你的最後一個條件應該僅僅是else

def print_popcorn_time(bag_ounces): 
    if bag_ounces < 3: 
     print("Too small") 
    elif bag_ounces > 10: 
     print("Tool large") 
    else: 
     print('{} seconds'.format(bag_ounces * 6)) 
+0

謝謝CoryKramer –

0
def print_popcorn_time(bag_ounces): 
    if bag_ounces < 3: 
     print'Too small') 
    elif bag_ounces > 10: 
     print('Too large') 
    else: 
     print(bag_ounces,':', (bag_ounces * 6), 'seconds') 

print_popcorn_time(7) 

你也可以去這是因爲你沒有使用時間函數。