[Tutor] Best way to write this countdown code
Thanks in advance as I've gotten wordy. I want to integrate the following working code into a website: beef_quantity = 28 ## Set before campaign starts. print('Original Beef Quantity: ') ## Displays the wording "Original Beef Quantity: " print (beef_quantity) ## Displays the beef quantity before order beef_choice = 'Quarter_Beef' ## Based on Customer's choice if beef_choice == 'Quarter_Beef': print('Quarter Beef selected') ## Notice of beef quantity ordered print('New Beef Quantity: ') ## Displays the wording "New beef quantity: " new_beef_quantity = beef_quantity - 1 ## Updates the beef quantity after order print(new_beef_quantity) ## Displays the updated beef quantity after order elif beef_choice == 'Half_Beef': print('Half Beef selected') ## Notice of beef quantity ordered print('New Beef Quantity: ') ## Displays the wording "New beef quantity: " new_beef_quantity = beef_quantity - 2 ## Updates the beef quantity after order print(new_beef_quantity) ## Displays the updated beef quantity after order else: print('Whole Beef selected') ## Notice of beef quantity ordered print('New Beef Quantity: ') ## Displays the wording "New beef quantity: " new_beef_quantity = beef_quantity - 4 ## Updates the beef quantity after order print(new_beef_quantity) ## Displays the updated beef quantity after order I also have two other similar code pieces (delivery.py and locker.py) that I want to integrate, but I'll put them in other emails. My end goal (which I still have to figure out) is to have the customer click on three sections of radio buttons and enter two text fields which will then display in an alert box where they can click a button to send them to PayPal for payment. The other part of this is that the number of available beef will countdown as each order is placed until zero s available which will then display "Sold Out!" Not sure if this is ALL python or part python and part javascript. Again, Thank you. Joe ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Request for help with code
Funny using a text editorand showed indented in my browser. Won't bother the list again. On Tue, Nov 6, 2018, 17:32 Joel Goldstick On Tue, Nov 6, 2018 at 6:17 PM Joseph Gulizia > wrote: > > > > Apologies for earlier errors when asking for help -- I am hopeful that > this > > shortened post displays properly: > > The code is Python 2... trying to solve why loop doesn't stop at given > > number of integersif I input request for 3 integersit keeps > asking > > for integer1...and keeps asking for input,,,so count isn't > > workingtrying to figure out why. Pointers please. > > > > import sys > > > > target_int=raw_input("How many integers?") > > > > try: > > target_int=int(target_int) > > except ValueError: > > sys.exit("You must enter an integer") > > > > # creates a collection (list) called ints > > > > ints=list() > > > > # keeps track of number of integers > > > > count=0 > > > > # Keep asking for an integer until we have the required number > > > > while count > new_int=raw_input("Please enter integer{0}:".format(count+1)) > > isint=False > > try: > > new_int=int(new_int) > > except: > > print("You must enter an integer") > > - > > > > > > On Tue, Nov 6, 2018 at 3:50 PM Joseph Gulizia > > wrote: > > > > > I'm using the bookazine "The Python Book" First Edition on pages > 13-14 it > > > gives the code (listed further below). > > > > > > It asks for user to state a given number of integers (for example > > > 4)...then user enters integers. It doesn't stop seeking input after > the > > > number requested thereby creating an infinite loop. > > > > > > - > > > CODE > > > - > > > > > > # Python Book Page_13.py > > > # Joe G. > > > > > > # several comment lines explain the code below it. > > > # Re-typing is good practice > > > > > > # We're going to write a program that will ask the user to input an > > > arbitrary > > > # number of intergers, store them in a collection, and then demonstrate > > > how the > > > # collection would be used in various control structures. > > > > > > # Used for the sys.exit function > > > import sys > > > # Requests number of intergers > > > target_int=raw_input("How many intergers?") > > > # By now, the variable target_int contains a string representtion of > > > # whatever the user typed. We need to try and convert that to an > interger > > > but > > > # be ready to # deal with the error if it's not. Otherwise the program > > > will > > > # crash > > > # Begin the error check > > > try: > > > target_int=int(target_int) > > > except ValueError: > > > sys.exit("You must enter an interger") > > > # creates a collection (list) called ints > > > ints=list() > > > # keeps track of number of intergers > > > count=0 > > > # Keep asking for an interger until we have the required number > > > while count > > new_int=raw_input("Please enter interger{0}:".format(count+1)) > > > isint=False > > > try: > > > new_int=int(new_int) > > > except: > > > print("You must enter an interger") > > > # Only carry on if we have an interger. If not, we'll loop again > > > # Notice below I use == which is different from =. The single equals > sign > > > is an > > > # assignment operator whereas the double equals sign is a comparison > > > operator. I would > > > # call it a married eguals signbut whenever single is mentioned I > have > > > to mention marriage. > > > > > > if isint==True: > > > # Add the interger to the collection > > > ints.append(new_int) > > > # Increment the count by 1 > > > count+=1 > > > # print statement ("using a for loop") > > > print("Using a for loop") > > > for value in ints: > > > print(str(value)) > > > # Or with a while loop: > > > print("Using a while loop") > > > # We already have the total above, but knowing the len function is very > > > # useful. > > > total = len(ints) > > > count = 0
Re: [Tutor] Request for help with code
Apologies for earlier errors when asking for help -- I am hopeful that this shortened post displays properly: The code is Python 2... trying to solve why loop doesn't stop at given number of integersif I input request for 3 integersit keeps asking for integer1...and keeps asking for input,,,so count isn't workingtrying to figure out why. Pointers please. import sys target_int=raw_input("How many integers?") try: target_int=int(target_int) except ValueError: sys.exit("You must enter an integer") # creates a collection (list) called ints ints=list() # keeps track of number of integers count=0 # Keep asking for an integer until we have the required number while count wrote: > I'm using the bookazine "The Python Book" First Edition on pages 13-14 it > gives the code (listed further below). > > It asks for user to state a given number of integers (for example > 4)...then user enters integers. It doesn't stop seeking input after the > number requested thereby creating an infinite loop. > > - > CODE > - > > # Python Book Page_13.py > # Joe G. > > # several comment lines explain the code below it. > # Re-typing is good practice > > # We're going to write a program that will ask the user to input an > arbitrary > # number of intergers, store them in a collection, and then demonstrate > how the > # collection would be used in various control structures. > > # Used for the sys.exit function > import sys > # Requests number of intergers > target_int=raw_input("How many intergers?") > # By now, the variable target_int contains a string representtion of > # whatever the user typed. We need to try and convert that to an interger > but > # be ready to # deal with the error if it's not. Otherwise the program > will > # crash > # Begin the error check > try: > target_int=int(target_int) > except ValueError: > sys.exit("You must enter an interger") > # creates a collection (list) called ints > ints=list() > # keeps track of number of intergers > count=0 > # Keep asking for an interger until we have the required number > while count new_int=raw_input("Please enter interger{0}:".format(count+1)) > isint=False > try: > new_int=int(new_int) > except: > print("You must enter an interger") > # Only carry on if we have an interger. If not, we'll loop again > # Notice below I use == which is different from =. The single equals sign > is an > # assignment operator whereas the double equals sign is a comparison > operator. I would > # call it a married eguals signbut whenever single is mentioned I have > to mention marriage. > > if isint==True: > # Add the interger to the collection > ints.append(new_int) > # Increment the count by 1 > count+=1 > # print statement ("using a for loop") > print("Using a for loop") > for value in ints: > print(str(value)) > # Or with a while loop: > print("Using a while loop") > # We already have the total above, but knowing the len function is very > # useful. > total = len(ints) > count = 0 > while count < total: >print(str(ints[count])) >count +=1 > > count = 0 > while count < total: > print(str(ints[count])) > count += 1 > > --- > END OF CODE > --- > Sample output: > > How many integers?3 > Please enter integer1:1 > Please enter integer1:2 > Please enter integer1:3 > Please enter integer1:a > You must enter an integer > Please enter integer1:4 > Please enter integer1:5 > Please enter integer1:6 > Please enter integer1:b > You must enter an integer > Please enter integer1: > (Keeps Looping) > > Thanks in advance > Joe > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Request for help with code
I'm using the bookazine "The Python Book" First Edition on pages 13-14 it gives the code (listed further below). It asks for user to state a given number of integers (for example 4)...then user enters integers. It doesn't stop seeking input after the number requested thereby creating an infinite loop. - CODE - # Python Book Page_13.py # Joe G. # several comment lines explain the code below it. # Re-typing is good practice # We're going to write a program that will ask the user to input an arbitrary # number of intergers, store them in a collection, and then demonstrate how the # collection would be used in various control structures. # Used for the sys.exit function import sys # Requests number of intergers target_int=raw_input("How many intergers?") # By now, the variable target_int contains a string representtion of # whatever the user typed. We need to try and convert that to an interger but # be ready to # deal with the error if it's not. Otherwise the program will # crash # Begin the error check try: target_int=int(target_int) except ValueError: sys.exit("You must enter an interger") # creates a collection (list) called ints ints=list() # keeps track of number of intergers count=0 # Keep asking for an interger until we have the required number while counthttps://mail.python.org/mailman/listinfo/tutor
[Tutor] Complications (Long) and Complicatiing Simple both Solved....
Original = -1 * max(-A, -B) print (Original) or max = -max(-A,-B) print(max) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Complications Take Two (Long) Frustrations.
Complicating a simple expression Coding Exercise: Complication Assume that the grader defines two variables A and B for you. Write a program which prints out the value min(A, B) However, there is a catch: your program is not allowed to use the min function. Instead, use max in a clever way to simulate min. Hint, Method 1 What is max(-A, -B)? Hint, Method 2 What is min(A, B)+max(A, B)? -- Code that gave best results but didn't work for negative numbers... -- Original = abs(max (-A, -B)) print (Original) -- Did not pass tests. Please check details below and try again. Results for test case 1 out of 5 Before running your code: We defined A equal to 35 and B equal to 45. Program executed without crashing. Program gave the following correct output: 35 Results for test case 2 out of 5 Before running your code: We defined A equal to 65 and B equal to 20. Program executed without crashing. Program gave the following correct output: 20 Results for test case 3 out of 5 Before running your code: We defined A equal to 48 and B equal to 63. Program executed without crashing. Program gave the following correct output: 48 Results for test case 4 out of 5 Before running your code: We defined A equal to 0 and B equal to 70. Program executed without crashing. Program gave the following correct output: 0 Results for test case 5 out of 5 Before running your code: We defined A equal to -64 and B equal to 0. Program executed without crashing. Program output: 64 Expected this correct output: -64 Result of grading: Your output is not correct. Spreadsheet examples: A BMin(A, B)Max(-A,- B) 10 55- 5 5 105- 5 9 129- 9 12 99- 9 22 37 22- 22 37 22 22- 22 45 68 45- 45 68 45 45- 45 - 6 15- 66 -15 6- 15 15 -80- 65- 80 80 -65- 80- 80 80 44-102-102 102 -44 102- 44 44 CS Assistant2 stated: Using the absolute value of the numbers will cause problems with this solution because sometimes the answer should be a negative number. However, when you calculate the absolute value of a number, that result will always be larger than any negative number. I would suggest you go back to your original table, but include some values for A and B that are negative numbers (A is negative, B is negative, A and B are both negative). See what numbers you get for min(A, B) and max(-A, -B) in those cases. Think about ways, other than absolute value, that will allow you to convert a negative number to a positive number and vice versa. I hope this helps. Sandy CS Assistant1 stated: Hi, Gathering this much data is a very good start! The two hints give two different approaches. So let me highlight the 4 most relevant columns: A BMin(A, B)Max(-A,- B) 10 5 5 -5 510 5 -5 912 9 -9 12 9 9 -9 223722 -22 372222 -22 456845 -45 684545 -45 What's the relationship between min(a, b), which you want but can't directly call, and max(-a, -b), which you can compute? Feel free to ask if another hint would help. Best, - Dave ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Complicating a simple expression (Python 3)
Complicating a simple expression Coding Exercise: Complication Assume that the grader defines two variables A and B for you. Write a program which prints out the value min(A, B) However, there is a catch: your program is not allowed to use the min function. Instead, use max in a clever way to simulate min. Hint, Method 1 What is max(-A, -B)? Hint, Method 2 What is min(A, B)+max(A, B)? My last code that worked somewhat --- Original = max(A, B) Opposite = max(-A, -B) Grader =max(-A,- B)+max(A, B) print (Grader) Did not pass tests. Please check details below and try again. Results for test case 1 out of 5 Before running your code: We defined A equal to 62 and B equal to 36. Program executed without crashing. Program output: 26 Expected this correct output: 36 Result of grading: Your output is not correct. Spreadsheet examples: ABMax(A, B)Min(A, B)Min(A, B)+Max(A, B)Max(A, B)+Max(A, B)Min(A, B)+Min(A, B) 105105152010 510105152010 912129212418 129129212418 22373722597444 37223722597444 4568684511313690 6845684511313690 Max(-A,- B)Max(-A,- B)+Max(A, B)Max(-A,- B)-Max(A, B) -55-15 -55-15 -93-21 -93-21 -2215-59 -2215-59 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Book recomandation!
I've found "Snake Wrangling for Kids" http://code.google.com/p/swfk/ by Jason Biggs an easy, fun and understandable free e-book. I also have started reading "Head First Programming" from O'Reilly which teaches programming using Python. I have others also but those two have been the easiest to read. YouTube also has many tutorials...some quite good. Joe On Thu, Jul 15, 2010 at 5:04 PM, David Hutto wrote: > On Thu, Jul 15, 2010 at 5:22 PM, Eric Hamiter wrote: > > Hi Daniel, > > > > As a fellow complete beginner, I have actually started a web site that > > details just this. I'm learning as I go and have tried to put together > > a curriculum of sorts that will helpfully guide other newbies as well, > > and reinforce what I'm learning for myself. > > > > http://letslearnpython.com/ > > > > Pardon my own plug, but you are exactly the audience member I am > > targeting. Everything I recommend with the exception of a paperback > > book is free to access. I'm adding more "lessons" as I go, and > > hopefully as I progress, I can make more specific recommendations. > > > > You are off to a great start by asking this list; I've found the > > people here are very friendly and extremely knowledgeable. > > > > Thanks, > > > > Eric > > > > > > On Thu, Jul 15, 2010 at 4:07 PM, Daniel > wrote: > >> Hello, I recently browsed the BeginnersGuide/NonProgrammers section of > the > >> Python website, but I have a question regarding it. With what book I > should > >> start learning Python? Or should I take them in the order they are > presented > >> there on the website?I have no previous programming experience, thanks. > >> > >> > >> > >> Have a great day! > >> > >> ___ > >> Tutor maillist - Tutor@python.org > >> To unsubscribe or change subscription options: > >> http://mail.python.org/mailman/listinfo/tutor > >> > >> > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > http://mail.python.org/mailman/listinfo/tutor > > > > I've done several, including Byte Of Python, as well as Dive into > python, and this is the best so far: > > inventwithpython.com/IYOCGwP_book1.pdf > > Although each individually might not make you an immediate expert. > Each helps you gain knowledge by repeating some of what you know, and > then offering a different program in which these fundamentals operate. > > So the more you practice the fundamentals within the books,(and don't > forget the online tutorials available), the more user friendly Python > becomes. > > . > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Learning python using Michael Dawson's book
I posted this two days ago (I thought to the list...but apparently not). I'm hopeful it helps in some way. I have the same book. Using a text editor and the underscore and dash keys and a few others...the program example is creating an ASCII art version on the words "Game Over". Type it manually probably means to type it out...NOT use copy and paste. Can't get it to work probably meansit doesn't display properly (as the book shows). What needs to be done is he needs to play with the spacing of the characters and different keys to get the "letters" drawn to display closer to the book's example. """ ___ |__ ___| _ _ | | / __\ / ___ \ _ | | | ||| | |___| | | |_| | | |__|| | /_ \/ \__/ \__| """ On Wed, May 19, 2010 at 2:38 AM, Andre Engels wrote: > On Tue, May 18, 2010 at 5:14 AM, Luke Paireepinart > wrote: > > Forwarding. Peter use reply-all don't reply offlist please. > > > > -- Forwarded message -- > > From: Peter > > Date: Mon, 17 May 2010 10:08:47 -0400 > > Subject: Re: [Tutor] Learning python using Michael Dawson's book > > To: Luke Paireepinart > > > > Hi, > > The result in the book has lettering like the following: > > _____ __ > > |||| || > > ||__|| || > > |__ | || > > |||| || > > |__||__| |__| > > Well, that's definitely not what the code would be producing, nor does > it seem to be related to what the example claims to be doing... > Perhaps instead of > > print( > """ > """ > ) > > which is a very strange idiom (though valid), you should write: > > print( > """ > _____ __ > |||| || > ||__|| || > |__ | || > |||| || > |__||__| |__| > """ > ) > > or perhaps you are looking at one example and the explanation of another? > > > > -- > André Engels, andreeng...@gmail.com > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] An interesting situation befalls me
As a new learner of programming I'd recommend Head First Programming "A learner's guide to programming, using the Python language" by O'Reilly. It is very basic. Joe On Sat, May 8, 2010 at 4:31 PM, Kirk Z Bailey wrote: > An instructor of mine is about to teach the FIRST EVER class in Python at > Saint Petersburg College; knowing I am a snakecharmer, he asked me for > referrals to online resources. > > Oh my. > > So I sent back this: > " > Ah, python., my fav obsession. First, the language website itself: > http://www.python.org/ > Natch, they offer a tutorial: > http://docs.python.org/tutorial/ > But this one is better for rank beginniners: > http://wiki.python.org/moin/BeginnersGuide/NonProgrammers > And there's another one here: > http://www.sthurlow.com/python/ > And a nice writeup on wikipedia: > http://en.wikipedia.org/wiki/Python_%28programming_language%29 > You may care to go teleport to planet python: > http://planet.python.org/ > And you can swim into it at diveintopython: > http://diveintopython.org/toc/index.html > " > > Now here is a chance to help influence this getting off on the right foot. > I can use reccomendations for texts for use in an introduction to Python > class, and I will condense it down and provide them to the good doctor. > > -- > end > > Very Truly yours, >- Kirk Bailey, > Largo Florida > > kniht+-+ > | BOX | +-+think > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor