On 03/08/17 11:05, Abdur-Rahmaan Janhangeer wrote: > me i cooked up :...
Yes that works too, especially if you don;t need access to the individual prices later. There are a couple of things to make it more Pythonic... > x = True > sum = 0 > > while (x==True): > a = input("input:") > if a =="exit": > x=False You could replace that with sum = 0 while True: a = input("input:") if a =="exit": break # exit the loop and > try: > sum += float(a) > except: > pass That's a risky strategy because if there is any error other than the one you anticipate then you will never know about it and ignore it. You should always try to specify the error(s) if possible: try: sum += float(a) except ValueError, TypeError: pass -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor