Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63643
| From | Alister <alister.ware@ntlworld.com> |
|---|---|
| Subject | Re: Constructive Criticism |
| Newsgroups | comp.lang.python |
| References | <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> <mailman.5286.1389300899.18130.python-list@python.org> <483bb41e-4e0b-4506-91b3-197e03477144@googlegroups.com> |
| Message-ID | <OAOzu.30216$B86.24469@fx05.am4> (permalink) |
| Organization | virginmedia.com |
| Date | 2014-01-10 08:56 +0000 |
On Thu, 09 Jan 2014 13:05:23 -0800, jeremiah valerio wrote:
> On Thursday, January 9, 2014 2:54:44 PM UTC-6, Christopher Welborn
> wrote:
>> On 01/08/2014 11:56 PM, jeremiahvalerio123@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 <cjwelborn@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()
you could improve your countdown function further by adding an optional
count vaule
def countdown(count=10):
for timeleft in reversed(1,count):
print ("Shutting down in {} Seconds".format(timeleft))
time.sleep(1)
--
Most people can't understand how others can blow their noses differently
than they do.
-- Turgenev
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Constructive Criticism jeremiahvalerio123@gmail.com - 2014-01-08 21:56 -0800
Re: Constructive Criticism Paul Pittlerson <menkomigen6@gmail.com> - 2014-01-08 22:06 -0800
Re: Constructive Criticism Ben Finney <ben+python@benfinney.id.au> - 2014-01-09 17:09 +1100
Re: Constructive Criticism jeremiah valerio <jeremiahvalerio123@gmail.com> - 2014-01-08 22:16 -0800
Re: Constructive Criticism Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-09 07:03 +0000
Re: Constructive Criticism Peter Otten <__peter__@web.de> - 2014-01-09 10:56 +0100
Re: Constructive Criticism jeremiah valerio <jeremiahvalerio123@gmail.com> - 2014-01-09 12:08 -0800
Re: Constructive Criticism Christopher Welborn <cjwelborn@live.com> - 2014-01-09 14:54 -0600
Re: Constructive Criticism jeremiah valerio <jeremiahvalerio123@gmail.com> - 2014-01-09 13:05 -0800
Re: Constructive Criticism Alister <alister.ware@ntlworld.com> - 2014-01-10 08:56 +0000
Re: Constructive Criticism jeremiah valerio <jeremiahvalerio123@gmail.com> - 2014-01-10 12:26 -0800
Re: Constructive Criticism Chris Angelico <rosuav@gmail.com> - 2014-01-11 07:34 +1100
Re: Constructive Criticism Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-10 21:24 +0000
csiph-web