2014-09-19 98 views
-4

有人可以幫我解決這個錯誤嗎?Python 3 IF語句

quantity = int(input('enter the the quantity:')) 

if quantity>=10 and quantity<=19: 

print('20% off') 
discount=99*0.2 
print('discount ', discount) 
purchase= quantity*99-dicount 
print('purchase is ', purchase) 

它說線5 IndentationError:預期的縮進塊

+0

Python中的分化非常重要。您必須縮進代碼才能將其放置在「if」循環中。 – Ffisegydd 2014-09-19 09:04:51

+3

這意味着:IndentationError:預計會出現一個縮進塊 – bereal 2014-09-19 09:05:36

+0

請在提問之前進行自己的研究。只要用錯誤信息搜索就會導致數以千計的教程,文章和文章描述問題,原因和解決方案。此外,在對SO進行提問之前,您應該對所編程的語言有最低限度的理解 - 事實上,您不知道Python的基本知識(控制流由縮進處理)意味着您缺少這個最低限度的理解,並且在問任何進一步的問題之前應該閱讀一些教程或書籍。 – l4mpi 2014-09-19 09:14:24

回答

1
if quantity>=10 and quantity<=19: 

    print('20% off') 
    discount=99*0.2 
    print('discount ', discount) 
    purchase= quantity*99-dicount 
    print('purchase is ', purchase) 

蟒使用縮進來定義代碼塊。你有if語句,但不縮進下方塊,這可能是空調

爲更好的解釋,在這個僞代碼:

if condition: 
    do A 
    do B 
do C 
do D 

A和B將取決於條件,但C和d會不。 if語句後至少需要一個縮進命令。它可能是簡單的回報,如果你還沒有什麼可以投入的話

+0

這也是一個很好的做法,避免空行:) – daveoncode 2014-09-19 09:07:14