Travis Risner

Greenhorn
+ Follow
since Jun 29, 2007
Travis likes ...
Python VI Editor
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Travis Risner

Hi, M. Gumblert,

Thanks for including the whole program, and for translating it to English.  That helps to focus the actual issue without other distractions.  Thanks also for including the comment in line 29 so we understand why the following two print statements have been included.

To understand why this code is failing, we need to understand the timing of when each statement is executed relative to the other statements in the loop.  Although the test for stopping the loop (at line 24) is physically before the rest of the code in the loop, the value received in the variable eaten is not tested until after all the code in the loop (ending with line 31) has run and the loop starts over.  Thus the split (at line 26 assumes that the answer in eaten has a comma, and  the code at line 28 assumes that meal now contains two values in the list.  

Hopefully this is enough of a nudge to work out a successful solution!

Travis
2 months ago
Thanks for setting our expectations!

Travis
2 months ago
Hi M. Gumblert,

Is the code shown extracted from a larger program?  Did you mean to have lines 8 and 9 indented at the same level as line 7?  Your description of what the code is supposed to do seems to indicate otherwise.  I also appreciate your wanting to translate the code for those of us who are language handicapped. Perhaps it would be helpful to temporarily try running the translated code to be sure it fails in the same way?

Thanks,
Travis
2 months ago
Hi Moritz,

Does the book Python Continuous Integration and Delivery include how to set up and use CI in GitLab specifically?  Also, does it cover how to set up CI from scratch on our own server?

Thanks,
Travis
2 months ago
Hi Wayne,

Since the first of this year or so, Glade (and the underlying wsPython libraries has become sufficiently stable to design full fledged GUI front ends for Python programs.  The difference is that Glade allows designing a GUI interface -- with a GUI tool.  Wth the other GUI libraries, such as Tcl/Tk, the interface has to be hand coded line by line.  (QT5 may have s similar tool but I have not investigated because of the licensing constraints.)  If someone knows of a GUI tool for Tcl/Tk that is similar to Glade, please add that to this thread.

There is an alternative for adding a simple GUI to a batch oriented Python tool.  That library is called PySimpleGUI (https://github.com/PySimpleGUI).  It supports several GUI frameworks and is quite usable if the desired GUI is not too complex.

3 months ago
Hi Vadim,

In addition to the other ways of hitting some limit, Python also has a builtin recursion default limit of 1000.  It can be changed by using sys.setrecursionlimit() if desired. However, for most Python programs, hitting that limit (or one of the others) means that the algorithm can be improved to avoid hitting any of these limits.  🙂
3 months ago
Hi Monica,

Wayne's suggestions are good.  Some folks enjoy learning from videos.  Others prefer seeing text.  In addition to the w3schools.com that Wayne mentioned, the Python web site itself has help and tutorials for beginners.  For an overview to help you get started, https://www.python.org/about/gettingstarted/ is a good place to look.  To go directly to a tutorial, https://docs.python.org/3/tutorial/ is the place to start.

May I also suggest that you start your learning with modern Python (Python 3)?  There are older versions of Python still available, but all of them will be "end-of-lifed" next year.  Although there are numerous videos, books, web sites, etc. that use Python 2, please keep looking for an equivalent in modern Python.  
3 months ago
Hi Wayne,

Yes the "if/elif/else" construct is often used to solve problems like this .  Python does not have a "case..end case" construct in the language so the code shown in the second example is the usual way to address this pythonically.  There are more sophisticated ways to let the data drive the selection, but may I suggest that you let that be a learning experience much further in your Python journey?  🙂
3 months ago
Hi Wayne,

Looks like you have taken a serious stab at the problem.  Here are a few "nudges" to help you along:

*    Python uses a certain construct to start programs which looks like
   
  The program may want to have a loop in this starting area to have it repeatedly call the drink menu function.

*    Passing the drink request information as parameters to the drink serving function is an excellent idea.  This avoids  the need for globals (which is usually avoided by experienced Python developers due to the complexity it adds to debugging).

*    Once the drink serving function has code added to handle non-alcoholic drinks, it can be used for any of the drink requests.

The program as is is at the moment is a great start.  Good luck with adding the rest of the functionality and with your journey to learn Python.  
3 months ago
Hi itsbinsha, (If I mangled your name, please let me  know.)

Would you re-post your code with the code tags surrounding it please?  I ask because it looks like the indentations of some lines got messed up.  It is not clear what part of the code is part of the class vs. what code is invoking it.

Thanks!
7 months ago
Grrr.     whereas  Using Idle or Jupyter is an easy way to  test code snippets.  (I should have used copy and paste rather than try to type it from memory.)
7 months ago
Oops, Jon I goofed.

The first modulo example should be  Sorry about that.  😟
7 months ago
Jon, first a question for Piet.

Piet, did you mean to use a forward slash rather than a backslash in your reply?

Jon, one of the things that changed from legacy python (v2) to modern python was division of integers using a single slash.  Since your previous posting of code appears to be modern python, I will focus on the modern python way.

Integer division using a single slash in modern python always results in a float, not an integer.  For example, not 0.  To get an integer result use the integer divide operator "//"  The same example with the integer divide operator:

The modulo operator works the same in both versions of python.   and  However, to tie it back to your problem, the modulo operator is calculating the number of occupied beds in the room.

Does that help clarify your computation?
7 months ago
Jon, I suspect  that your problem "went away" because you converted the input values from strings to numbers.  For example, the value of numberOfNights in line 25 is a string, not a number.  So the problem may have been that you were attempting to multiply a string by a float, rather than an integer by a float.  Does that make sense?
7 months ago
Hi Stanramsey,

When this program executes the line "window.mainloop()", it hands control over to the part of Tkinter that begins watching for user input, such as a mouse click or a key press.  Control never gets to the lines beyond until Tkinter receives a "quit" signal of some kind.  Thus, runprogram1 and runprogram2 will never execute while the GUI is displayed.  Instead, to get progX and progY to run, the command parameter of your buttons need to invoke them directly.

HTH!
7 months ago