i know i'm stupid but i have tried everything to get one line of text working, 
i have written out pseudo and read every website.....now i am getting this 
error............
Traceback (most recent call last):  File "F:\VTOS ATHLONE\PYTHON_VTOS\foreign 
exchange\f_ex4 - Copy.py", line 24, in <module>    main()  File "F:\VTOS 
ATHLONE\PYTHON_VTOS\foreign exchange\f_ex4 - Copy.py", line 14, in main    
while amount<50:UnboundLocalError: local variable 'amount' referenced before 
assignment>>> 


def exchange(cash_in):    euro=1    dollar=1.35    base=50    if cash_in>base:  
      totalreturn=cash_in*dollar    else:        totalreturn=0    return 
totalreturn
amount=0def main():    while amount<50:        amount = raw_input(float('how 
much do you want to change:'))    if amount<50:        total=0        print 
'enter an amount over 50: '    else:        total=exchange(amount)        print 
'Your exchange comes to: ',total
 

  

Adrian Kelly 
1 Bramble Close

Baylough

Athlone

County Westmeath

0879495663


From: [email protected]
Date: Thu, 17 Nov 2011 16:53:59 -0600
Subject: Re: [Tutor] please help - stuck for hours
To: [email protected]
CC: [email protected]

On Thu, Nov 17, 2011 at 4:32 PM, ADRIAN KELLY <[email protected]> wrote:








thanks very much, great response really really appreciated it and now i 
understand. i hate to ask again but can you see why it won't print the  'enter 
and amount over 50' in the right place??


Computers are unfailingly stupid machines. They will do whatever wrong thing 
you tell them to do every single time. 

 <snip>def main():    amount=0    while amount<50:        amount = input('how 
much do you want to change:')

        print 'enter an amount over €50: '    else:        
total=exchange(amount)        print 'Your exchange comes to: ',total


Sometimes it helps writing out the logic in steps before you translate it to 
code. In this case my guess is that these are the steps you want:
  1. Get a value from the user (you're still using input - stop that, it's 
dangerous! input is   only a good function in 3.x where it replaces raw_input)

   2. If the value is less than 50, tell the user to enter an amount > 50 and 
repeat step 1
  3. Otherwise, exchange the amount and display that.
Right now, these are the steps that you're doing:


  1. Get a value from the user
  2. Display the error message
  3. If the value is < 50, go to 1
  4. exchange the amount


  5. display the amount.
HTH,Wayne                                         
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to