Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63571 > unrolled thread
| Started by | jeremiahvalerio123@gmail.com |
|---|---|
| First post | 2014-01-08 21:56 -0800 |
| Last post | 2014-01-10 21:24 +0000 |
| Articles | 13 — 9 participants |
Back to article view | Back to comp.lang.python
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
| From | jeremiahvalerio123@gmail.com |
|---|---|
| Date | 2014-01-08 21:56 -0800 |
| Subject | Constructive Criticism |
| Message-ID | <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> |
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 "
[toc] | [next] | [standalone]
| From | Paul Pittlerson <menkomigen6@gmail.com> |
|---|---|
| Date | 2014-01-08 22:06 -0800 |
| Message-ID | <81a9c283-4940-4ef4-9a79-ed8f118c5532@googlegroups.com> |
| In reply to | #63571 |
I think the only winning move is not to play.
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-01-09 17:09 +1100 |
| Message-ID | <mailman.5238.1389247771.18130.python-list@python.org> |
| In reply to | #63571 |
jeremiahvalerio123@gmail.com writes: > Hi, hows it going I've been self teaching myself python Welcome to Python, and to this discussion forum! > 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. Some constructive criticism: * Please make an effort to write readable English here. A run-on sentence like the above makes it seem as though you don't care enough for our help to make your message easily readable. * Please paste the code in your actual message, rather than directing to an ephemeral website. This is so that the discussion will always have the code for context when later readers view it. Once you re-post your program and describe its purpose, I'm sure there will be some responses giving feedback. -- \ “My girlfriend has a queen sized bed; I have a court jester | `\ sized bed. It's red and green and has bells on it, and the ends | _o__) curl up.” —Steven Wright | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | jeremiah valerio <jeremiahvalerio123@gmail.com> |
|---|---|
| Date | 2014-01-08 22:16 -0800 |
| Message-ID | <8aacf3b7-2e7f-4d74-80b1-faf3de09ac71@googlegroups.com> |
| In reply to | #63573 |
On Thursday, January 9, 2014 12:09:17 AM UTC-6, Ben Finney wrote: > jeremiahvalerio123@gmail.com writes: > > > > > Hi, hows it going I've been self teaching myself python > > > > Welcome to Python, and to this discussion forum! > > > > > 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. > > > > Some constructive criticism: > > > > * Please make an effort to write readable English here. A run-on > > sentence like the above makes it seem as though you don't care enough > > for our help to make your message easily readable. > > > > * Please paste the code in your actual message, rather than directing to > > an ephemeral website. This is so that the discussion will always have > > the code for context when later readers view it. > > > > Once you re-post your program and describe its purpose, I'm sure there > > will be some responses giving feedback. > > > > -- > > \ “My girlfriend has a queen sized bed; I have a court jester | > > `\ sized bed. It's red and green and has bells on it, and the ends | > > _o__) curl up.” —Steven Wright | > > Ben Finney yea sorry about this screw up "i know its not the best the coding is not the best but" and i'm new to forums never posted so i will take all your input and re-post maybe later thank you.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-01-09 07:03 +0000 |
| Message-ID | <mailman.5241.1389251106.18130.python-list@python.org> |
| In reply to | #63574 |
On 09/01/2014 06:16, jeremiah valerio wrote: > On Thursday, January 9, 2014 12:09:17 AM UTC-6, Ben Finney wrote: >> jeremiahvalerio123@gmail.com writes: >> >> >> >>> Hi, hows it going I've been self teaching myself python >> >> >> >> Welcome to Python, and to this discussion forum! >> >> >> >>> 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. >> >> >> >> Some constructive criticism: >> >> >> >> * Please make an effort to write readable English here. A run-on >> >> sentence like the above makes it seem as though you don't care enough >> >> for our help to make your message easily readable. >> >> >> >> * Please paste the code in your actual message, rather than directing to >> >> an ephemeral website. This is so that the discussion will always have >> >> the code for context when later readers view it. >> >> >> >> Once you re-post your program and describe its purpose, I'm sure there >> >> will be some responses giving feedback. >> >> >> >> -- >> >> \ “My girlfriend has a queen sized bed; I have a court jester | >> >> `\ sized bed. It's red and green and has bells on it, and the ends | >> >> _o__) curl up.” —Steven Wright | >> >> Ben Finney > > yea sorry about this screw up "i know its not the best the coding is not the best but" and i'm new to forums never posted so i will take all your input and re-post maybe later thank you. > Before you repost would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-01-09 10:56 +0100 |
| Message-ID | <mailman.5252.1389261357.18130.python-list@python.org> |
| In reply to | #63571 |
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 "
> time.sleep(1)
> import time
> print("Closing in 9 ")
> time.sleep(1)
> import time
> print("Closing in 8 ")
- You should import modules just once, at the beginning of your script.
- Repetetive tasks are best handled with a for-loop, e. g.:
>>> import time
>>> for seconds_left in reversed(range(1, 10)):
... print("Closing in", seconds_left, "seconds")
... time.sleep(1)
...
Closing in 9 seconds
Closing in 8 seconds
Closing in 7 seconds
Closing in 6 seconds
Closing in 5 seconds
Closing in 4 seconds
Closing in 3 seconds
Closing in 2 seconds
Closing in 1 seconds
> user_input = input("\nWhos your favorite Football team? \n 1.Arizona
> Cardinals\n 2.Atlanta Falcons\n 3.Baltimore Ravens\n 4.Buffalo Bills\n
> 5.Miami Dolphins\n 6.Minnesota Vikings \n 7.New England Patriots \n
> 8.New Orleans Saints \n 9.Carolina
[snip]
Python offers triple-quoted strings which may include newline literals:
user_input = input("""
Who's your favorite Football team?
1. Arizona Cardinals
2. Atlanta Falcons
...
""")
> if user_input == "1" :
> print("\nThey suck! BYE!")
>
> elif user_input == "2" :
> print("\nThey suck! BYE!")
>
> elif user_input == "3" :
> print("\nThey suck!BYE!")
[snip]
Ignoring the typos you are taking the same action for all inputs but "17".
So:
if user_input != "17":
print()
print("They suck! BYE!")
You should give some thought how unexpected user input like "", "123",
"whatever" should be handled.
> elif user_input == "no" :
> print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.")
> import time
> time.sleep(1)
> import time
> print("Closing in 9 ")
> time.sleep(1)
> import time
> print("Closing in 8 ")
> time.sleep(1)
> import time
OK, you are doing the count-down thing twice -- time to write a function,
say countdown(), that you can put where you need a count-down instead of the
repetetive code.
[toc] | [prev] | [next] | [standalone]
| From | jeremiah valerio <jeremiahvalerio123@gmail.com> |
|---|---|
| Date | 2014-01-09 12:08 -0800 |
| Message-ID | <f5360fa8-89d3-4042-a1bb-07e622ef4ab5@googlegroups.com> |
| In reply to | #63589 |
On Thursday, January 9, 2014 3:56:37 AM UTC-6, Peter Otten wrote:
> 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 "
>
>
>
> > time.sleep(1)
>
> > import time
>
> > print("Closing in 9 ")
>
> > time.sleep(1)
>
> > import time
>
> > print("Closing in 8 ")
>
>
>
> - You should import modules just once, at the beginning of your script.
>
>
>
> - Repetetive tasks are best handled with a for-loop, e. g.:
>
>
>
> >>> import time
>
> >>> for seconds_left in reversed(range(1, 10)):
>
> ... print("Closing in", seconds_left, "seconds")
>
> ... time.sleep(1)
>
> ...
>
> Closing in 9 seconds
>
> Closing in 8 seconds
>
> Closing in 7 seconds
>
> Closing in 6 seconds
>
> Closing in 5 seconds
>
> Closing in 4 seconds
>
> Closing in 3 seconds
>
> Closing in 2 seconds
>
> Closing in 1 seconds
>
>
>
> > user_input = input("\nWhos your favorite Football team? \n 1.Arizona
>
> > Cardinals\n 2.Atlanta Falcons\n 3.Baltimore Ravens\n 4.Buffalo Bills\n
>
> > 5.Miami Dolphins\n 6.Minnesota Vikings \n 7.New England Patriots \n
>
> > 8.New Orleans Saints \n 9.Carolina
>
> [snip]
>
>
>
> Python offers triple-quoted strings which may include newline literals:
>
>
>
> user_input = input("""
>
> Who's your favorite Football team?
>
> 1. Arizona Cardinals
>
> 2. Atlanta Falcons
>
> ...
>
> """)
>
>
>
> > if user_input == "1" :
>
> > print("\nThey suck! BYE!")
>
> >
>
> > elif user_input == "2" :
>
> > print("\nThey suck! BYE!")
>
> >
>
> > elif user_input == "3" :
>
> > print("\nThey suck!BYE!")
>
> [snip]
>
>
>
> Ignoring the typos you are taking the same action for all inputs but "17".
>
> So:
>
>
>
> if user_input != "17":
>
> print()
>
> print("They suck! BYE!")
>
>
>
> You should give some thought how unexpected user input like "", "123",
>
> "whatever" should be handled.
>
>
>
> > elif user_input == "no" :
>
> > print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.")
>
> > import time
>
> > time.sleep(1)
>
> > import time
>
> > print("Closing in 9 ")
>
> > time.sleep(1)
>
> > import time
>
> > print("Closing in 8 ")
>
> > time.sleep(1)
>
> > import time
>
>
>
> OK, you are doing the count-down thing twice -- time to write a function,
>
> say countdown(), that you can put where you need a count-down instead of the
>
> repetetive code.
Thanks so much,exactly what i was looking for
thanks for taking the time.
[toc] | [prev] | [next] | [standalone]
| From | Christopher Welborn <cjwelborn@live.com> |
|---|---|
| Date | 2014-01-09 14:54 -0600 |
| Message-ID | <mailman.5286.1389300899.18130.python-list@python.org> |
| In reply to | #63571 |
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
[toc] | [prev] | [next] | [standalone]
| From | jeremiah valerio <jeremiahvalerio123@gmail.com> |
|---|---|
| Date | 2014-01-09 13:05 -0800 |
| Message-ID | <483bb41e-4e0b-4506-91b3-197e03477144@googlegroups.com> |
| In reply to | #63634 |
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()
[toc] | [prev] | [next] | [standalone]
| From | Alister <alister.ware@ntlworld.com> |
|---|---|
| Date | 2014-01-10 08:56 +0000 |
| Message-ID | <OAOzu.30216$B86.24469@fx05.am4> |
| In reply to | #63636 |
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
[toc] | [prev] | [next] | [standalone]
| From | jeremiah valerio <jeremiahvalerio123@gmail.com> |
|---|---|
| Date | 2014-01-10 12:26 -0800 |
| Message-ID | <808615c3-ce1a-46ae-b875-55cd2f58b3b3@googlegroups.com> |
| In reply to | #63643 |
On Friday, January 10, 2014 2:56:14 AM UTC-6, Alister wrote:
> 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
So always think of the if's and possibility's that
other people might do, thanks for you input.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-01-11 07:34 +1100 |
| Message-ID | <mailman.5302.1389386088.18130.python-list@python.org> |
| In reply to | #63660 |
On Sat, Jan 11, 2014 at 7:26 AM, jeremiah valerio <jeremiahvalerio123@gmail.com> wrote: > So always think of the if's and possibility's that > other people might do, thanks for you input. Also think of the possibility that someone will read your post and its quoted text. Please get off Google Groups, or if you must keep using it, clean up your quotes - they're all coming out double-spaced. You may find the mailing list easier to use: https://mail.python.org/mailman/listinfo/python-list ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-01-10 21:24 +0000 |
| Message-ID | <mailman.5306.1389389094.18130.python-list@python.org> |
| In reply to | #63660 |
On 10/01/2014 20:26, jeremiah valerio wrote: For the second time of asking would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing, thanks. Failing that, please arm yourself with a semi-decent email client, there are umpteen to choose from. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web