-1
endFlag = False
while endFlag == False:
     fruits= ['apple','cherry','banana','kiwi', 'lemon','pear', 'peach','avocado']
     num = int(input('please select a fruit with the number associated with it   ' ))
     if num == 0:
            print (fruits[0])
     elif num ==1:
            print(fruits[1])
     elif num == 2:
           print(fruits[2])
     elif num == 3:
            print(fruits[3])
     elif num == 4:
           print(fruits[4])
     elif num == 5:
          print(fruits[5])
      elif num == 6:
         print (fruits[6])
    elif num == 7:
        print(fruits[7], ',please enjoy your fruit!')
    else:
print('enter another fruit please, that one is not available')
VendingMachine = input("would you like to repeat the program again? Yes/No  ")
if VendingMachine == 'N':
   endFlag = True

This code shows "SyntaxError: multiple statements found while compiling a single statement" and I need help because I do not know why.

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • 3
    Does this answer your question? [SyntaxError: multiple statements found while compiling a single statement](https://stackoverflow.com/questions/21226808/syntaxerror-multiple-statements-found-while-compiling-a-single-statement) – Bill Huang Dec 02 '20 at 01:59
  • 1
    its pure indentation issue. Please recheck indentations. – huzzzus Dec 02 '20 at 02:18

1 Answers1

2

The problem may be the ident thing you did at the end. The if, the elifs and the else should have the same identation.

Also the code can be improve like this:

#put fruits outside the loop so it only runs once
fruits= ['apple','cherry','banana','kiwi', 'lemon','pear', 'peach','avocado']
endFlag =  False

while not endFlag:
    num = int(input('please select a fruit with the number associated with it')

    if num >= 0 and num<len(fruits): #You can also use try/except here
        print(fruit[num])
    else:
        print('enter another fruit please, that one is not available')

    VendingMachine = input("would you like to repeat the program again? Yes/No ")

    if VendingMachine[0] == 'N': #if user input is 'No' your code fails
        endFlag = True
Luis Díaz
  • 82
  • 4