- Strength to Increase Rep
- +15
- Strength to Decrease Rep
- -3
- Upvotes Received
- 916
- Posts with Upvotes
- 812
- Upvoting Members
- 325
- Downvotes Received
- 66
- Posts with Downvotes
- 60
- Downvoting Members
- 38
IT Pro doing Eng-Fin-Eng translations
- Interests
- Python, Mojo, Julia, multiculturalism, translation
- PC Specs
- TUF Gaming 10th gen laptop and various desktops
3,386 Posted Topics
Re: More concisely the same as vegaseat wrote could be writen: ''' coinflip102.py flip a coin 100 times and count heads and tails ''' import random tails = sum(random.choice(['head', 'tail']) == 'tail' for k in range(100)) print("""The Number of heads was {heads} The Number of tails was {tails}""".format(tails=tails, heads=100-tails)) | |
Re: Hint: CODE button must be pushed before pasting code! | |
Re: Paste a piece of code which is unclear to you and we can clarify it's meaning in pseudocode. Do not post externally, but include as normal attachment or preferably just code block. The files in your rar file seemed to be OK, except wrong file types and one of the … | |
Re: Post your code and we will check it out. It is not very hard if you keep your head straight! If you have learned about dictionaries, simplest to operate with is to index dictionary like: board['b2'] or board['b',2] and get user input like: b2, 4 | |
Re: Your display routine is at least too complicated and line 12 does not make sense. Same shorter: [CODE]def count(sticks): print("* %s *" % (sticks * '|')) count(33) [/CODE] Indents of lines 64 and 65 does not make sense. I see for example "How many sticks would you like to pick … | |
Re: [Here](http://matrixprogramming.com/2011/03/linear-solve-in-python-numpy-and-scipy) for example is one example about solving by Gaussian elimination with numpy/scipy with reference to LAPACK libraries. Scipy also has matrix IO routines: http://docs.scipy.org/doc/scipy/reference/tutorial/io.html You might like to install Enthought Canopy Python which has numerous libraries ready installed: https://www.enthought.com/products/canopy/ | |
Re: How about [CODE]now = str(datetime.datetime.now())[/CODE] | |
Re: [code] # program that checks that the username and password are correct # username = input("Please enter your username : ") password = input("Please enter your password : ") print ("Greetings," , username, "you are now logged in now with a password") command = input("Please type a command :") if … | |
Re: n is undefined. I do not understand your int statement. I would index a tuple of the values instezd of nested if.. Sorry but mobile posting is not working at the moment correctly. Could you post the error you are getting and how you are using the function. | |
Re: You are missing essential part calling the main! Otherwise it looks like working, even input is in text window. | |
Re: I do not know pack method so well, but here is how I do it with pack: [CODE]from Tkinter import * import tkFont def killme(): root.quit() root.destroy() root=Tk() dFont=tkFont.Font(family="Arial", size=30) lb=Text(root, width=16, height=5, font=dFont) lb.pack(side=LEFT, fill=BOTH, expand = YES) yscrollbar=Scrollbar(root, orient=VERTICAL, command=lb.yview) yscrollbar.pack(side=RIGHT, fill=Y) lb["yscrollcommand"]=yscrollbar.set root.mainloop() [/CODE] | |
Re: I do not get the problem, only I got not found error from mag function found in code, so I replaced it with distance from origin. I did some renaming to make the program more "PEP8 understandable" [CODE]from __future__ import division from math import * class Point(object): def __init__(self, x=0.0, … | |
Re: OK, here is a really optimized version for this classic problem. This is not originally mine (but have done very similar). It utilizes the fact that primes > 4 are 1(mod 6) or 5(mod 6). Actually I editted it a lot now before posting to be more according to format … | |
Re: So you have not learned the syntax, good place to start to learn it is to go through the tutorial at http://docs.python.org/tutorial/index.html | |
Re: I would prefer to have functions themselves as first value and just call it instead of using eval. be sure to rename the functions according to choice. Best naming would be to use verb and if need to join words in name use _. Do not use capital letters. | |
Re: That is because unnecessary update of the screen weakens the quality of the display. Maybe not, or only with slower computer, but it is good practice to avoid unnecessary refresh. Especially when you do more action on screen than just changing number. | |
Re: Please include the error messages. The variable must of course be global variable in the python file. At least saving the value to text file to be read by the script should work. | |
Re: Value of words will be the method for splitting strings. Maybe that is not what you want. | |
Re: Gribouillis means that obviously those two functions have no business in being in the class Player. Interestingly I have exactly same functions in module called games for a Blackjack game from one book, without the class Player. in range(low, high) is not the world's most efficient way to check value … | |
Re: Why you are not calling the mainloop at last line? Shouldn't the parameter to parent init be self? | |
This is one small snippet of after event usage. You could express if you find this kind of simple code to be usefull as snippet. Notice also vegaseat's sticky message threads in begining of Python forum in addition to code snippets. | |
Re: Agreed, WaltP. As example, here is what Code::Blocks AStyle plugin makes out of your code #include<iostream> #include<cstdio> #include<conio.h> using namespace std; int weight[20][20],visited[20],d[20],p[20]; int v,e; void creategraph() { int i,j,a,b,w; cout<<"Enter number of vertices: "; cin>>v; cout<<"\nEnter number of edges: "; cin>>e; for(i=1; i<=v; i++) for(j=1; j<=v; j++) weight[i][j]=0; for(i=1; … | |
Re: What was the best program you have done this far? Of course you have to do some kind of design of the program algorithm first and be able to do the task yourself and able to list all steps of it before teaching the computer to do it. Are you … | |
Re: Are you sure that you initialize the midi system like in this snippet before playing the file? | |
Re: Everything should work as long as you replace the print command with print function, manually or by 2to3. More shortly: [CODE]# find the last line, change to a file you have with open('test.txt') as myfile: print (list(myfile)[-1]) [/CODE] | |
Re: Of course it could be considered user responsibility, but I do not personally like that the calculator does not allow to continue from result and saves formula to memory instead of evaluating the result automatically. For example: 10/3 M-> = result: 3.333333 * M<- = result: *10/3.0first char not in … | |
Re: Is that 3.2 3.2.2 as there was an issue with input statement with 3.2.1? Probably not reason though, at that problem would make program OK in IDLE and not OK in direct excecution. | |
Re: Good luck, we are always ready to help, you only have to post in your code and explain where you have difficulty. | |
Re: Are you sure you need while for this job. BTW it has no else part not to talk about elif. And in you new version while condition is always True as <condition> or -2 is always True. | |
Re: Would it maybe easier to use my code snippet for text file based database (actualy card file would be more proper term) | |
Re: M+ does addition to existing contents in memory, MS stores there [CODE] M+ =+ MS =[/CODE] | |
Re: And how then would you learn anything? See the forum rules or shorter version from my signature! There is plenty of code snippets in sticky threads and code archive for you to adapt yourself and learn how to actually do it yourself. | |
Re: You could just ignore the error data by try.. except. self is not good name for regular parameter as it is normally used in oo programs for the instance itself. Tony | |
Re: I think you are still here: > Show the > iterative development of the individual solutions with suitable testing throughout the process. Test > the final products and evaluate your solutions against the detailed requirements you identified in the > analysis. I see no indication that this is the case … | |
Re: This is what I got from theantonio.neal.39's post by tinkering: from tkinter import * def move(): if message.winfo_x() + message.move >= message.x_limit or message.winfo_x() + message.move < 0: message.move = -message.move message.place(x=message.winfo_x() + message.move) message.after(message.delay, move) gui = Tk() gui.geometry('8000x100+1+600') gui.title('ALERTS') gui.config (bg = 'blue') message = Label(gui, text = … | |
Sometimes we want to not split by every space character, but we want to split only on those outside of brackets and quotes. This way we can have for example quoted string as single argument for command. EDIT: 1. Added hierarchical nesting of same kind of brackets. 2. Bunching multiple … | |
Re: It is possible to make it one liner, but the dictionary approach is clearer or using few more if statements. Maybe you should anyway normalize the case of input to take both 'am' and 'AM' and accept hours with ' ' or '0' in front and also extra blanks at … | |
Re: So for some reason I prefer to use Python instead of re language for this. Actually one of my first code snippets here was of same subject. [url]www.daniweb.com/software-development/python/code/280071/1209215#post1209215[/url] | |
Re: Also you can use namedtuples, and csv module is not really needed for simple cases. [CODE]from collections import namedtuple filein = open("sample.dat") datadict={} headerline = [f.strip() for f in filein.readline().split(',')] print headerline Dataline=namedtuple('Dataline',headerline) for data in filein: data=[f.strip() for f in data.split(',')] print(data) d=Dataline(*data) datadict[d.id]=d print datadict['123'].email for key,value in … | |
Re: You have here very complete algorithm, but you should show effort of implementing it, even if you do not get everything right. After we can assist you in debugging or point weak points to concentrate in. | |
Re: You have tagged various programming languages, but I do not get really your point, can you give specific question or your problem. Anything showing were you are stuck and we could advice you. | |
Re: How is this connected with Python? | |
Re: Basically I agree with her divinity's judgement. [QUOTE=thines01;1638376]#3 (lots of conditions) [CODE] #include "stdafx.h" #include <stdlib.h> int CheckNum(int num) { int iCount = 0; while(num > 0) { num -= 2; iCount ++; } return iCount; } bool isOdd(int num) { return CheckNum(num) != CheckNum(num-1); } void main(void) { char … | |
Re: how about changing to append mode 'a' instead of 'w' Also looks like you have same file open twice, line 26 and 28 for writing. Finally you are not really using the csv module, but doing by hand at line 30. | |
Re: I would prefer to go with more general approach, and definately not use the dangerous input in Python 2: def withdraw_money(): denoms = (100, 50, 20, 10, 5, 2, 1) while True: try: withdraw = int(raw_input('amount of money: ')) break except Exception as e: print('Incorrect input: %s' % e) # … | |
Re: Yes, you must just make the number split from file line numeric and check if that line had line_value in it if it is lower than current line_value, as you seem to have line_value always increasing and the lines with second value higher do not need checked. You might add … | |
Re: Also, see the code snippet on checking numeric input at: [url]http://www.daniweb.com/code/snippet284490.html[/url] | |
Re: [B]Gigasecond vs nanosecond[/B] Your computer has worked so hard that you want to give it generous holiday of one second by replacing it in it's job. The computer calculates your program one operation per nanosecond, so you have little much job to do. How much real time must you spend … | |
| |
Re: These are applicable to programming in general (Python -> import this) > The Zen of Python, by Tim Peters > > Beautiful is better than ugly. > Explicit is better than implicit. > Simple is better than complex. > Complex is better than complicated. > Flat is better than nested. … |
The End.