Python Forum
Feedback on my first solo coding project please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feedback on my first solo coding project please
#1
Hi

Below is the code from my first attempted project, it works (its maths based as I am a maths teacher)

If anybody has a few spare minutes I would appreciate someone running it and having a go.
Also, please critique my code, there are probably millions of ways to make it neater

Also, sorry if there is an easier/better way to upload/show code.

Thanks in advance

Nick

import time
my_num = 0
print("Think of a number between 1 and 63")
time.sleep(8)
print("OK, Lets go.")
time.sleep(2)
print("Please ensure you answer with a capital Y or N or this program will not work")
print("Is your number in the group of numbers below?")
time.sleep(2)
print("")
print("1    3    5    7    9    11   13   15")
print("17   19   21   23   25   27   29   31")
print("33   35   37   39   41   43   45   47")
print("49   51   53   55   57   59   61   63")
return1 = input("Y/N?")
if return1 == "Y":
    my_num = my_num + 1
time.sleep(2)
print("")
print("")
print("Is your number in this group of numbers ?")
time.sleep(2)
print("")
print("2    3    6    7    10   11   14   15")
print("18   19   22   23   26   27   30   31")
print("34   35   38   39   42   43   46   47")
print("50   51   54   55   58   59   62   63")
return2 = input("Y/N?")
if return2 == "Y":
    my_num = my_num + 2
time.sleep(2)
print("")
print("")
print("Is your number in this third group of numbers ?")
time.sleep(2)
print("")
print("4    5    6    7    12   13   14   15")
print("20   21   22   23   28   29   30   31")
print("36   37   38   39   44   45   46   47")
print("52   53   54   55   60   61   62   63")
return3 = input("Y/N?")
if return3 == "Y":
    my_num = my_num + 4
time.sleep(2)
print("")
print("")
print("Half way there. Is your number in this group of numbers ?")
time.sleep(2)
print("")
print("8    9    10   11   12   13   14   15")
print("24   25   26   27   28   29   39   31")
print("40   41   42   43   44   45   46   47")
print("56   57   58   59   60   61   62   63")
return4 = input("Y/N?")
if return4 == "Y":
    my_num = my_num + 8
time.sleep(2)
print("")
print("")
print("One more after this one. Is your number in this group of numbers ?")
time.sleep(2)
print("")
print("16   17   18   19   20   21   22   23")
print("24   25   26   27   28   29   30   31")
print("48   49   50   51   52   53   54   55")
print("56   57   58   59   60   61   62   63")
return5 = input("Y/N?")
if return5 == "Y":
    my_num = my_num + 16
time.sleep(2)
print("")
print("")
print("Last one. Is your number in this group of numbers ?")
time.sleep(2)
print("")
print("32   33   34   35   36   37   38   39")
print("40   41   42   43   44   45   46   47")
print("48   49   50   51   52   53   54   55")
print("56   57   58   59   60   61   62   63")
return6 = input("Y/N?")
if return6 == "Y":
    my_num = my_num + 32
print("")
print("")
print("")
print("OK, let me think...")
time.sleep(10)
print("I think the number you thought of was ...")
print(str(my_num))
time.sleep(10)
print("")
print("")
print("")
print("I dont know how to end my coding, so it is just pausing. This message will self destruct in 10 seconds")
time.sleep(10)
Reply
#2
Nick, your script is interesting, and very unpythonic. It got me thinking if you had a better program structure this could scale, say a number between 1 and 126. How do you convert it to a more pythonic way? Create functions for repetitive operations;
Quote:return1 = input("Y/N?")
if return1 == "Y":
my_num = my_num + 1
time.sleep(2)
more on functions function
list comprehension you are basically creating a list of numbers
more on lists list s and data sets
now you'll need to format the lists do a search on converting a list into rows and columns this will also be a great candidate for a function and the list as an argument.
Your script has a great idea now you need to support it with code.
Reply
#3
I've never understood newbies fascination with time.sleep. Normally people strive to make their programs faster, time execution, perform profiling to identify bottlenecks.... Yet every other newbie uses time.sleep for some effect :-)

(Mar-31-2020, 02:41 PM)w4ldom4ths Wrote: "I dont know how to end my coding, so it is just pausing. This message will self destruct in 10 seconds"

one way to wait before ending script execution and closing cmd window is to take user input;
input('Press any key...')
of course, if I understand what the "problem" is, you can always open cmd/terminal window and run the script, not double click on it.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Thank you both for the feedback.

Am trying to improve my knowledge of and use functions in my code. I am finding that I am repeating the same instructions throughout my code.


Thanks again.
Reply
#5
Quote: I am finding that I am repeating the same instructions throughout my code
many ways to repeat instructions 1 for loops:
for loops
2 range range loop
and 3 while loops while loops
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020