Constructive Criticism

  • Thread starter jeremiahvalerio123
  • Start date
J

jeremiahvalerio123

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 iwould 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 "
 
J

jeremiah valerio

(e-mail address removed) writes:






Welcome to Python, and to this discussion forum!








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.
 
P

Peter Otten

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.:
.... 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.
 
J

jeremiah valerio

(e-mail address removed) 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 "



import time
print("Closing in 9 ")

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.:



... 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

import time
print("Closing in 9 ")

import time
print("Closing in 8 ")

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.
 
C

Christopher Welborn

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)
 
J

jeremiah valerio

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 <[email protected]>

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()
 
J

jeremiah valerio

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top