[Tutor] How do I fix this Invalid Mode?

Nathan Pinno falcon3166 at hotmail.com
Sat Dec 17 20:00:33 CET 2005


Here is the latest error:
The Currency Exchange Program
By Nathan Pinno
 
Traceback (most recent call last):
  File "D:\Python24\exchange.py", line 27, in -toplevel-
    store = open('exch.txt', 'b')#load
IOError: invalid mode: b
 
and the latest code:
import pickle
rates = {'can_us' : 0.80276,
         'us_can' : 1.245702,
         'can_euro' : 1.488707,
         'euro_can' : 0.671724}
 
def menu():
    print "1. Change Canadian currency into American."
    print "2. Change American currency into Canadian."
    print "3. Change Canadian currency into Euros."
    print "4. Change Euros into Canadian currency."
    print "5. Update exchange rates."
    print "9. Save and Exit"
 
def exchange_update():
    print "1. Update Canadian to US rate."
    print "2. Update US to Canadian rate."
    print "3. Update Canadian to Euro rate."
    print "4. Update Euro to Canadian update."
    print "5. Main menu"
 
def menu_choice():
    return int(raw_input("Which option? "))
 
print "The Currency Exchange Program"
print "By Nathan Pinno"
store = open('exch.txt', 'b')#load
exch = pickle.load(store)
store.close()
while 1:
    menu()
    menu_option = menu_choice()
    if menu_option == 1:
        can = float(raw_input("Canadian $"))
        print "US $",can*rates['can_us']
    elif menu_option == 2:
        us = float(raw_input("US $"))
        print "CAN $",us*rates['us_can']
    elif menu_option == 3:
        can = float(raw_input("CAN $"))
        print "Euros",can*rates['can_euro']
    elif menu_option == 4:
        euro = float(raw_input("Euros"))
        print "CAN $",euro*rates['euro_can']
    elif menu_option == 5:
        while 1:
            exchange_update()
            sub = menu_choice()
            if sub == 1:
                new_can = float(raw_input("New CAN-US Exchange rate: "))
                rates['can_us'] = new_can
                print "Exchange rate successfully updated!"
            elif sub == 2:
                new_us = float(raw_input("New US-CAN Exchange rate: "))
                rates['us_can'] = new_us
                print "Exchange rate successfully updated!"
            elif sub == 3:
                new_cxr = float(raw_input("New CAN-Euro Exchange rate: "))
                rates['can_euro'] = new_cxr
                print "Exchange rate successfully updated!"
            elif sub == 4:
                new_euro = float(raw_input("New Euro-CAN Exchange rate: "))
                rates['euro_can'] = new_euro
                print "Exchange rate successfully updated!"
            elif sub == 5:
                break
    elif menu_option == 9:
        store = open("exch.txt", 'wb') #save
        pickle.dump(exch, store)
        store.close()
        break
print "Goodbye."
 
How do I fix it this time?
 
Thanks,
Nathan Pinno,
 <http://www.the-web-surfers-store.com/> 
MSN Messenger: falcon3166 at hotmail.com
Yahoo! Messenger: spam_swatter31
AIM: f3mighty
ICQ: 199020705  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051217/d3339b3c/attachment.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 862 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20051217/d3339b3c/attachment.gif


More information about the Tutor mailing list