Re: [Tutor] Vending machine program
On 04/01/13 17:47, bob gailer wrote: > Further selections can be made if there is enough credit. This is confusing. You could drop that line with no ill effect. I am not sure what it even means. It seemed straightforward enough to me Bob. If you put in $10 and buy a candy bar for $6 you have $4 credit left. You can then choose another item provided it costs less than $4. It just implies another level of loop in the design. In fact given the detail of the spec its hard to see what we could add by way of help until the OP produces some code to critique. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] stuck on a new program
On Fri, Jan 4, 2013 at 11:15 PM, Ghadir Ghasemi < ghasemm...@leedslearning.net> wrote: > Hi guys I recently created a binary to denary and denary to binary > convertor program. It is pretty much finished but I can't get it to work. > Can you spot the fault in it please and tell me how it coul be fixed? > > print("==") > print("1 = binary to denary") > print("2 = denary to binary") > > > return = input("enter an option) > menu_option = get_option() > > > while True: > menu_option = get_option() > > if menu_option == '1': > a = int(input('please enter an 8 bit binary number: '),2); > print("the result is", a) > > if menu_option == '2': > b= bin(int(input('please enter a denary number: ')));print("the > result is", b) > > There are several errors here, in fact. The first error you made is not including the output of your program when you attempted to run it. There should have been an error message of some form, with an indicator of where the error happened. For example, if I run the program on the command line, I get this: File "test.py", line 6 return = input("enter an option) ^ SyntaxError: invalid syntax always, always always include any error messages you get when you send an e-mail to this list or other programming lists. It may not be absolutely necessary for small programs like this, but it still saves everyone a bunch of time. And if there are no error messages, tell us what you expected to happen, and what happened instead. "I can't get it to work" is the least useful problem description in the history of mankind, giving absolutely zero helpful information that can be used to solve the problem. Help us help you, please. The error indicated by python has to do with keywords: python has several "keywords" which are used to indicate certain structures in the language. Examples are "while", "if", and "return". These keywords have a special meaning in the language, and can thus not be used as variable names. You tried to use return as a variable name, which is why the syntax error shows up on that line. There are other mistakes in this program: the get_option() function, for example, which you have used in this program, is not defined anywhere. You used it but never told python what it means. Thus if I corrected the return error and tried to run the program again, python would complain about the "get_option" name not existing (or did you not include the entire program in this e-mail? That would be another mistake. If you did not include an error, and we cannot run the program to see what it is, helping you becomes very difficult indeed). So assuming we fixed that missing function, the program now runs without error messages. However, there are four lines at the bottom that will never be reached by the computer. Why not? Look at these lines above it: while True: menu_option = get_option() what does it do? Well, "while True" describes a loop that runs forever. The only line inside the loop is "menu_option = get_option(). So, the program will keep running that line for eternity, and never reach the two "if" statements below. Can you fix it now? HTH, Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] stuck on a new program
Hi guys I recently created a binary to denary and denary to binary convertor program. It is pretty much finished but I can't get it to work. Can you spot the fault in it please and tell me how it coul be fixed? print("==") print("1 = binary to denary") print("2 = denary to binary") return = input("enter an option) menu_option = get_option() while True: menu_option = get_option() if menu_option == '1': a = int(input('please enter an 8 bit binary number: '),2); print("the result is", a) if menu_option == '2': b= bin(int(input('please enter a denary number: ')));print("the result is", b) Thank you so much ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble importing Paramiko
Hi Walter, Adding Python location to sytem path works. :-) Thanks a lot! Ufuk 2013/1/4 Walter Prins > Hi Ufuk, > > On 4 January 2013 13:03, Ufuk Eskici wrote: > >> Hello Hugo, >> >> I removed all related softwares from my PC and tried to re-install >> everyting. >> >> At the last step, this command fails (instructions: >> http://vijaymurthy.blogspot.com/2011/03/installing-paramiko-for-windows.html >> ) >> >> >> C:\paramiko-1.7.4>python setup.py build --compiler=mingw32 bdist_wininst >> 'python' is not recognized as an internal or external command, >> operable program or batch file. >> >> > Erm, this is actually telling you the problem directly: The system cannot > find the "python" command. To explain: the Windows command interpreter > has a list of directories (folders) that it searches for matching programs > when you enter a command at the commant prompt. When it cannot find any > program matching the name entered as a command, it duly displays the above > message. > > Here's some background/references for this so you can improve your > understanding of what's going on (as a programmer you really need to > understand this stuff): > > http://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them > http://www.voidspace.org.uk/python/articles/command_line.shtml > > So, the implication of you receiving this message is that your Python > interpreter location is not on this system path list. To add it, click > "Start", then right click "Computer", then "Properties", then click > "Advanced system settings" on the left, click the "Environment variables" > button at the bottom of the dialog, then look for the variable named "Path" > under the section "System variables", click on it to select it then click > the "Edit" button, then add ";C:\Python27\" to the existing path list > (without the quotes and making sure to include the separator semicolon). > Click "OK" and exit all the dialogs. Then re-open a command prompt, and at > the prompt type "python" with no arguments and press enter. This should > now open up the Python interpreter which if successful will prove that the > PATH change was done succesfully. > > Aside, if you install Python using ActiveState's distribution, this step > is done automatically for you. In case you're interested, you can get > ActiveState's Python distribution here: > http://www.activestate.com/activepython/downloads > Note that although they request you to register, it is not obligatory. > > HTH, > > Walter > > > ___ > 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] invalid literal for int error in Game loop
Ciaran Mooney wrote: Thanks for the feedback. Steve, If I set the FPS to a default of say 30, the game seems to run at this default FPS=30 regardless of the key pressed in the function. Dave, If I remove the the default value at the start of the function and add it to elif in the loop I get the following error: Traceback (most recent call last): File "/Users/callanmooneys/Desktop/Pythoin Programmes/Aliens Game/dodger ver 3 instructons.py", line 139, in FPS = difficultyLevel() File "/Users/callanmooneys/Desktop/Pythoin Programmes/Aliens Game/dodger ver 3 instructons.py", line 50, in difficultyLevel return FPS UnboundLocalError: local variable 'FPS' referenced before assignment I wondered if i could set FPS to nether a string or integer and just declare it by setting FPS=None but I get the following error: Traceback (most recent call last): File "/Users/callanmooneys/Desktop/Pythoin Programmes/Aliens Game/dodger ver 3 instructons.py", line 301, in mainClock.tick(FPS) TypeError: a float is required Cheers Ciaran As far as I understood your problem, it seems that you need the difficulty level to be changed at the player's will during the game. In this case, the function gets called many times, maybe at every game loop. If this is true, you need a global FPS value to be changed by the player's choice, not one that you create inside the function. Try this: # put the line below out of the function definition and out of the game loop, usually together with other default program settings FPS = 30 # you want the game to be beginner-friendly, don't you? def difficultyLevel(): global FPS windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT),pygame.FULLSCREEN) windowSurface.fill(BACKGROUNDCOLOUR) drawText('LEVEL OF PLAY', font3, windowSurface, (WINDOWWIDTH/6), (WINDOWHEIGHT/6)) drawText('B: Your an absoulute Begineer', font3, windowSurface, (WINDOWWIDTH/6)-100, (WINDOWHEIGHT/6)+100) drawText('M: Not Too Snazy', font3, windowSurface, (WINDOWWIDTH/6)-100, (WINDOWHEIGHT/6)+150) drawText('H: Deathwish' ,font3,windowSurface, (WINDOWWIDTH/6)-100, (WINDOWHEIGHT/6)+200) pygame.display.update() for event in pygame.event.get(): if event.type == QUIT: terminate() if event.type == KEYDOWN: if event.key == ord('b'): FPS = 30 elif event.key == ord('m'): FPS = 70 elif event.key == ord('h'): FPS = 120 return FPS ... then let us know. Hope that helps Francesco ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Vending machine program
On 01/04/2013 06:34 AM, Ghadir Ghasemi wrote: H I wanted to create a program called vending machine and I wondered if you could do it so I can find out how to do it. > Here is how it should work like: > > A food vending machine accepts 10p, 20p, 50p and £1 coins. > One or more coins are inserted and the current credit is calculated and displayed. > A product is selected from those available. The system checks to see if there is enough credit to purchase the product chosen. > If there is not enough credit the system displays an error message. > If there is enough credit it dispenses the product, updates the credit available and displays the remaining credit. > Further selections can be made if there is enough credit. > The vending machine simulation should have five products and prices. Design, code, test and evaluate a program for this simulation. > > Thank you > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > I would suggest a general design with VendingMachine class with these properties: - product list (if you don't need to handle running out of products) - credit (int, in pence) - method to list products and credit - method to add to credit - method to buy a product A separate class that handles user interface: main loop, accepting the commands: add amount, select product; a method that runs continuously until a valid command is provided & then the command is returned. In the main loop, products are listed, user provides the command, command is delegated to one of VendingMachine methods and then loop goes back to the beginning. Hope this helps, -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Vending machine program
On 1/4/2013 6:34 AM, Ghadir Ghasemi wrote: H I wanted to create a program called vending machine and I wondered if you could do it so I can find out how to do it. Here is how it should work like: A food vending machine accepts 10p, 20p, 50p and £1 coins. One or more coins are inserted and the current credit is calculated and displayed. A product is selected from those available. The system checks to see if there is enough credit to purchase the product chosen. If there is not enough credit the system displays an error message. If there is enough credit it dispenses the product, updates the credit available and displays the remaining credit. Further selections can be made if there is enough credit. The vending machine simulation should have five products and prices. Design, code, test and evaluate a program for this simulation. Where did you get this assignment? What prior programming experience do you have? As already mentioned we prefer to not do your work for you. Further selections can be made if there is enough credit. This is confusing. You could drop that line with no ill effect. I am not sure what it even means. How far did you get in the steps suggested? Did you attempt a design? -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help about to how many times the function called
On 1/4/2013 4:25 AM, Steven D'Aprano wrote: On 04/01/13 20:17, lei yang wrote: Hi experts I have a function will print PASS status def print_pass(t_elapsed): """ Print PASS to stdout with PASS (green) color. """ print_stdout(bcolors.PASS + "PASS" + bcolors.ENDC + " (%.2f s)" % t_elapsed) I want to calculate the pass number, so I want to get " how many times this function called" It is unclear to me what you want to do with the pass number or what PASS means or where bcolors comes from. If you don't need to refer to the pass number outside the function another way (better IMHO): def print_pass(t_elapsed, how_many_times=0): """ Print PASS to stdout with PASS (green) color. """ how_many_times += 1 print_stdout(bcolors.PASS + "PASS" + bcolors.ENDC + " (%.2f s)" % t_elapsed) I for one would appreciate a more complete explanation. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble importing Paramiko
Hi Ufuk, On 4 January 2013 13:03, Ufuk Eskici wrote: > Hello Hugo, > > I removed all related softwares from my PC and tried to re-install > everyting. > > At the last step, this command fails (instructions: > http://vijaymurthy.blogspot.com/2011/03/installing-paramiko-for-windows.html > ) > > > C:\paramiko-1.7.4>python setup.py build --compiler=mingw32 bdist_wininst > 'python' is not recognized as an internal or external command, > operable program or batch file. > > Erm, this is actually telling you the problem directly: The system cannot find the "python" command. To explain: the Windows command interpreter has a list of directories (folders) that it searches for matching programs when you enter a command at the commant prompt. When it cannot find any program matching the name entered as a command, it duly displays the above message. Here's some background/references for this so you can improve your understanding of what's going on (as a programmer you really need to understand this stuff): http://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them http://www.voidspace.org.uk/python/articles/command_line.shtml So, the implication of you receiving this message is that your Python interpreter location is not on this system path list. To add it, click "Start", then right click "Computer", then "Properties", then click "Advanced system settings" on the left, click the "Environment variables" button at the bottom of the dialog, then look for the variable named "Path" under the section "System variables", click on it to select it then click the "Edit" button, then add ";C:\Python27\" to the existing path list (without the quotes and making sure to include the separator semicolon). Click "OK" and exit all the dialogs. Then re-open a command prompt, and at the prompt type "python" with no arguments and press enter. This should now open up the Python interpreter which if successful will prove that the PATH change was done succesfully. Aside, if you install Python using ActiveState's distribution, this step is done automatically for you. In case you're interested, you can get ActiveState's Python distribution here: http://www.activestate.com/activepython/downloads Note that although they request you to register, it is not obligatory. HTH, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble importing Paramiko
Hello Hugo, I removed all related softwares from my PC and tried to re-install everyting. At the last step, this command fails (instructions: http://vijaymurthy.blogspot.com/2011/03/installing-paramiko-for-windows.html ) C:\paramiko-1.7.4>python setup.py build --compiler=mingw32 bdist_wininst 'python' is not recognized as an internal or external command, operable program or batch file. C:\paramiko-1.7.4> What is wrong? 2013/1/2 Hugo Arts > On Wed, Jan 2, 2013 at 10:48 AM, Ufuk Eskici wrote: > >> Hello Steven, >> >> I've written this before: >> >> "My Python version is 2.7.3 and it is installed in "C:\Python27 (on the >> web, it says Paramiko-1.7.4 is supported with Python 2.7)" >> >> so I'm using the correct Python verion (2.7.3). But I dont know why I'm >> getting errors during Paramiko installation as I mentioned before. >> >> > That is very interesting, because when you tried my earlier suggestion to > use "python setup.py install" the error messages you gave us came very > clearly from python 3.3, not python 2.7.3. Look more closely at some of > those error messages: > > > File "c:\python33\lib\site-packages\paramiko-1.7.4-py3.3. > egg\paramiko\transport.py", line 353 > >out = ' > > ^ > > SyntaxError: invalid syntax > > C:\python33 is definitely not C:\python27. That looks to me like you have > two versions of python installed on your machine, both python 3.3 and > python 2.7. I an only make an educated guess at this, but probably when you > invoke python on your command line, it's actually python 3.3 that is > started. You can verify this by simply starting a command line, going to > your C:\ directory, typing in python, and looking at the version number > that comes up. If it is indeed true you have two versions of python > installed, try the installation step again, but now make absolutely sure > you use the correct version of python to run the setup script, like this: > > C:\python27\python.exe setup.py install > > That will use python 2.7 to run the installation script, and *that* in > turn will make sure paramiko is actually installed for the correct python > version. > > HTH, > Hugo > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Vending machine program
On Fri, Jan 4, 2013 at 12:34 PM, Ghadir Ghasemi < ghasemm...@leedslearning.net> wrote: > H I wanted to create a program called vending machine and I wondered if > you could do it so I can find out how to do it. > No. This list is meant to help people with specific questions about their python programs. If you make an attempt at writing this program and get stuck or have questions on how to proceed, we will be happy to give you hints and help you out. But we won't do your work for you. Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Vending machine program
H I wanted to create a program called vending machine and I wondered if you could do it so I can find out how to do it. Here is how it should work like: A food vending machine accepts 10p, 20p, 50p and £1 coins. One or more coins are inserted and the current credit is calculated and displayed. A product is selected from those available. The system checks to see if there is enough credit to purchase the product chosen. If there is not enough credit the system displays an error message. If there is enough credit it dispenses the product, updates the credit available and displays the remaining credit. Further selections can be made if there is enough credit. The vending machine simulation should have five products and prices. Design, code, test and evaluate a program for this simulation. Thank you ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help about to how many times the function called
On 04/01/13 20:17, lei yang wrote: Hi experts I have a function will print PASS status def print_pass(t_elapsed): """ Print PASS to stdout with PASS (green) color. """ print_stdout(bcolors.PASS + "PASS" + bcolors.ENDC + " (%.2f s)" % t_elapsed) I want to calculate the pass number, so I want to get " how many times this function called" any help? how_many_times = 0 def print_pass(t_elapsed): """ Print PASS to stdout with PASS (green) color. """ global how_many_times how_many_times += 1 print_stdout(bcolors.PASS + "PASS" + bcolors.ENDC + " (%.2f s)" % t_elapsed) -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] help about to how many times the function called
Hi experts I have a function will print PASS status def print_pass(t_elapsed): """ Print PASS to stdout with PASS (green) color. """ print_stdout(bcolors.PASS + "PASS" + bcolors.ENDC + " (%.2f s)" % t_elapsed) I want to calculate the pass number, so I want to get " how many times this function called" any help? Lei ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] writing effective unittests
On 4 January 2013 03:34, Alan Gauld wrote: > On 04/01/13 07:10, Brian van den Broek wrote: > ... > >> confirm that the code works as intended when written, but that it >> continues to work several moths later > > > moths? They'll be the bugs I guess? > > Sorry I couldn't resist :-) :-) I shouldn't like to meet the man who could. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] writing effective unittests
On 04/01/13 07:10, Brian van den Broek wrote: ... confirm that the code works as intended when written, but that it continues to work several moths later moths? They'll be the bugs I guess? Sorry I couldn't resist :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor