On Thursday, January 9, 2014 2:54:44 PM UTC-6, Christopher Welborn wrote: > On 01/08/2014 11:56 PM, jeremiahvalerio...@gmail.com wrote: > > > Hi, hows it going I've been self teaching myself python, and i typed up > > this small script now i know its not the best the coding is not the best > > but i would like to know of ways to make a small script like this better so > > all constructive critisim is Welcome. > > > > > > > > > > > > Here is the link to the code > > > > > > " http://pastebin.com/5uCFR2pz " > > > > > > > I'm not sure if someone already pointed this out, but imports only need > > to be done once. Usually at the beginning of the file, but not always. > > In your case I would say yes, at the beginning. > > > > import sys > > import time > > > > def countdown(seconds):' > > # start at 'seconds' and count down with a for-loop > > for i in range(seconds, 0, -1): > > # print the current second (i) > > print('closing in {} seconds.'.format(i)) > > # sleep for one second (no need to import time again). > > time.sleep(1) > > > > # Example usage: > > print('hello') > > # Prints the countdown. > > countdown(10) > > sys.exit(0) > > -- > > > > - Christopher Welborn <cjwelb...@live.com> > > http://welbornprod.com
Mr.Peter Otten did "- You should import modules just once, at the beginning of your script. " -Peter Otten With his help this is what i have now def countdown(): import time for seconds_left in reversed(range(1, 10)): print("Closing in", seconds_left, "seconds") time.sleep(1) exit() if user_input == "yes" : user_input = input("\nGreat what should we talk about?\nSports\nWeather") elif user_input == "no" : print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.") countdown() -- https://mail.python.org/mailman/listinfo/python-list