-2

Hi I'm making a simple code that is due soon. I'm using Wing IDE 4.1.3-1 and I keep getting this message when I run my program code

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \UXXXXXXXX escape (, line 4)

Here is my program:

#=====================================================================
# Program:      Calculating Sales
# Programmer:   Viet-Anh Tran
# Date:         2-14-2012
#               July 1, 2011 - Revised for Python 3
# Abstract:     This program processes highest sales, lowest sales,
#               and averages the total numnber of sales. Each
#               salesperson will be asked enter the amount they sold
#               and the price of each sale.
#=====================================================================

def main():
    #create variable to control loop
    keep_going = 'y'
    #process each salperson's sales
    while keep_going == 'y' or keep_going == 'Y':
        #use a function to process sales
        show_sales()
        keep_going = input("would you like to calculate another salesperson's" +
        "sales? (enter y or Y as yes to continue) ")
#define show_sales
def show_sales():
    #ask for name of salesperson
    name = input("What is the salesperson's name? ")
    #ask for first sales amount
    print('Enter', name, "'s first sale amount: ")
    first_sale = float(input())
    #when assigning a value for first sale make sure its bewtween 1-25000
    while first_sale < 1 or first_sale > 25000:
        #prompt error message if it does not meet within range
        print('ERROR: First sale amount must fall in the range of $1-$25,000.')
        #ask user again for CORRECT amount
        print('Please enter', name, "'s correct first sale amount:")
        first_sale = float(input())
    #assign all total highest and lowest sales to first sale
    total_sale = first_sale
    highest_sale = first_sale
    lowest_sale = first_sale
    #ask for the total number of sales
    print('Are there any more sales? If so, type in the total number of sales:')
    number_sales = int(input())
    #create a loop
    for sale in range(2, number_sales + 1):
        print('What is', name, "'s next sales amount?")
        sales_amount = float(input())
        #again make sure that it is within range and ask the correct amount again
        while sales_amount < 1 or first_sale > 25000:
            print('ERROR: Sale amount must fall in the range of $1-$25,000.')
        print('Please enter', name, "'s correct sale amount:")
        sales_amount = float(input())
        #accumulate the total sales
        total_sales += sales_amount
        #this assigns the lowest and highest value to the correct variable
        if sales_amount > highest_sale:
            highest_sale = sales_amount
        if sales_amount < lowest_sale:
            lowest_sale = sales_amount
    #calculate average and print highest, lowest, and average
    average_sales = total_sales / number_sales
    print(name, "'s highest sale: $", format(highest_sale, ',.2f'), sep='')
    print(name, "'s lowest sale: $", format(lowest_sale, ',.2f'), sep='')
    print(name, "'s sale on average: $", format(average_sale, ',.2f'), sep='')
Jörg Beyer
  • 3,631
  • 21
  • 35
  • that is probably not the reason for your SyntaxError, but please don't use float for money calculations - that is not robust. – Jörg Beyer Feb 14 '12 at 21:55
  • is that the exact error message? to which source line is it corresponding? What do you do to see this Error message? – Jörg Beyer Feb 14 '12 at 21:56
  • okay here is the full error:Traceback (most recent call last): File "", line 4, in SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \UXXXXXXXX escape (, line 4) [evaluate TranVPR5.py] – Oiugghog Jkhkh Feb 14 '12 at 21:59
  • Sort of works here. You have assigned to `total_sale` first and later use `total_sales`, and at the end you try to print `average_sale` which hasn't been defined before, but no encoding problems. – Daniel Fischer Feb 14 '12 at 21:59
  • you are mixing "" and '' in an nearly unreadable way, e.g. the print('What is', name, "'s next sales amount?"). And you can terminate multiline strings with 3x quotes ("""). – Jörg Beyer Feb 14 '12 at 22:04
  • Actually I figured it out. I didn't add a main() at the end of the code. I fail LOL – Oiugghog Jkhkh Feb 15 '12 at 04:49

2 Answers2

2

File "<string>" shows that your program is being run through exec, most likely passed there with a byte string. So that's probably an oversight in the IDE.

The cause of error may be special characters somewhere in your name. Python 3 should handle that anyway, but Wing IDE seems to try and make code the compatible with Python 2... and fails.

Of course, this is mostly speculation, but you should consider running your script in command line, without any IDE. I did, and it worked.

Oleh Prypin
  • 33,184
  • 10
  • 89
  • 99
0

This is a bug in Wing 4.1.3 that can be fixed by using Check for Updates in the Help menu.

Rais Alam
  • 6,970
  • 12
  • 53
  • 84
Wingware
  • 896
  • 5
  • 12