0

I am trying to get this program to open the file and print a list of whether its a CD or a DVD and the amount they owe and the customers name, but I get a syntax error with printing the customers name

this is the syntax error I'm getting -

invalid syntax: BWHW7.pyw, line 25, pos 37 in file c:\Users\Benjaguin\Desktop\python\BWHW7.pyw, line 25 print(customer_name, end='\t')

This is code i used..

 CD_SPINDLE = 16.50
    DVD_SPINDLE = 21.75

    def main():
       cd_spindle_counter = 0
       dvd_spindle_counter = 0

        print("Guest Name \tSpindle Code\tAmount of Spindles\tAmount Due")
       print()

       try:
           infile = open('spindles.txt', 'r')

           customer_name = infile.readline()

           while customer_name != '':
               customer_name = customer_name.rstrip('\n')
               print(customer_name, end='\t')

               spindle_code = infile.readline()
               spindle_code = room_type.rstrip('\n')
               print(spindle_code, end='\t')

               spindle_amount = infile.readline()
               spindle_amount = int(spindle_amount)
               print(spindle_amount, end='\t')

               if spindle_code == "c" or spindle_Code == "C":
                   payment_due = spindle_amount * CD_SPINDLE
                   cd_spindle_counter += 1
               elif spindle_code == "d" or spinlde_code == "D":
                   payment_due = spindle_amount * DVD_SPINDLE
                   dvd_spindle_counter += 1
               else:
                   payment_due = 0

               total_spindle_payment += payment_due

               if payment_due ==0:
                   print('invalid code')
               else:
                 print('$', format(payment_due, '8,.2f'))

               guest_name = infile.readline()

           infile.close()

           print()
           print('total number of CD spindles sold:   ', cd_spindle_counter)
           print('total number of DVD spindles sold:    ',dvd_spindle_counter)
           print()
           print('total CD/DVD purchases:   ', end='')
           print('$', format(total_spindle_payment, ',.2f'), sep='')

       except IOError:
           print('an error occured trying to open or read spindle.txt')

    main()
2
  • 3
    Are you running python 2 or 3 ? end argument for print should be only supported in python 3 Commented Nov 15, 2016 at 4:59
  • Your indentation, though legal, is not very consistent. Besides, you should not tag Python2 and Python3, because each of those tag is aimed at version-specific problems. Commented Nov 15, 2016 at 5:03

1 Answer 1

1

I think the problem was due to inconsistent indentation. I've corrected that (used an indentation of 2 consistently), and now it's working:

CD_SPINDLE = 16.50
DVD_SPINDLE = 21.75

def main():
  cd_spindle_counter = 0
  dvd_spindle_counter = 0

  print("Guest Name \tSpindle Code\tAmount of Spindles\tAmount Due")
  print()
  try:
    infile = open('spindles.txt', 'r')

    customer_name = infile.readline()

    while customer_name != '':
      customer_name = customer_name.rstrip('\n')
      print(customer_name, end='\t')

      spindle_code = infile.readline()
      spindle_code = room_type.rstrip('\n')
      print(spindle_code, end='\t')

      spindle_amount = infile.readline()
      spindle_amount = int(spindle_amount)
      print(spindle_amount, end='\t')

      if spindle_code == "c" or spindle_Code == "C":
        payment_due = spindle_amount * CD_SPINDLE
        cd_spindle_counter += 1
      elif spindle_code == "d" or spinlde_code == "D":
        payment_due = spindle_amount * DVD_SPINDLE
        dvd_spindle_counter += 1
      else:
        payment_due = 0

      total_spindle_payment += payment_due

      if payment_due ==0:
        print('invalid code')
      else:
        print('$', format(payment_due, '8,.2f'))

      guest_name = infile.readline()

    infile.close()

    print()
    print('total number of CD spindles sold:   ', cd_spindle_counter)
    print('total number of DVD spindles sold:    ',dvd_spindle_counter)
    print()
    print('total CD/DVD purchases:   ', end='')
    print('$', format(total_spindle_payment, ',.2f'), sep='')

  except IOError:
    print('an error occured trying to open or read spindle.txt')

main()
Sign up to request clarification or add additional context in comments.

5 Comments

I fixed some minor spelling mistakes and indentation but now I'm getting ValueError: invalid literal for int() with base 10: '' in regards to this part spindle_amount = infile.readline() spindle_amount = int(spindle_amount) print(format(spindle_amount, '3.0f'),'\t') i tried making it a float but it doenst work either
In that case you need to show me the text file you're taking inputs from.
Can you share the contents of the file in text ?
yeah, sorry Rex Carr C 10 Mark Downs D 3 Wayne Storm E 9
Is this all in one line ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.