304 Posted Topics

Member Avatar for Yozuru

Some remarks... I would say that a function is auxiliary if it is called and used by a limited set of functions (methods, other callables) and does not provide functionality(meaning) on its own. If you write some date arithmetic module, then isleapyear appears not to be an auxiliary function. It …

Member Avatar for slate
0
5K
Member Avatar for birinci2012

Yes, it is worse then the infamous: `not re.match(r"^1?$|^(11+?)\1+$", "1" * number_to_test)` birinci: There is nothing wrong with this algo. But computers (more precisely: functions using stack in the operating system) are not built the way, they can process this program efficiently. It is a leaking abstraction. Google it.

Member Avatar for slate
0
997
Member Avatar for brittany.nelson.526
Member Avatar for Sarfaraz_1

Please read a basic python tutorial, write down in normal words what you expect form this class, and repost your code. Issues: * The some method's naming contradict the methods documentation (is_empty, is_full) * Different methods with the same code. * Semantically problematic code (insert) * I do not understand …

Member Avatar for TrustyTony
0
726
Member Avatar for bunyonb

I think this is the wrong question. Allow me to be philosofical. I advise you to consider the following wisdom: **A good programmer is smart and gets things done.** Consider this as a buddhist [quote](http://viewonbuddhism.org/resources/buddhist_quotes.html). **Smart** means to be brutally honest to yourself about whether you understand something or not. …

Member Avatar for bunyonb
0
236
Member Avatar for victorkvarghese

I always learn new things. 1 lakh = 10**5 This is the recommended approach to open a file and handle it since python 2.7: with open("filename") as f: <handle content of the file> Otherwise rrashkin's solution is good for linear search. You say binary search in contrast to linear search. …

Member Avatar for slate
0
3K
Member Avatar for oh.m.song.1

> as close to the below as possible. As close to [that](http://code.activestate.com/recipes/576830-analog-clock/)? Are you learning turtle? Are you expected to do that in turtle?

Member Avatar for slate
0
145
Member Avatar for Rebecca_2

Please be more specific. Some ideas: > 1. numbering the lines in the file? with open('output.txt', 'r') as f for line_number, line in enumerate(f): pass # do something with the line > 2. finding this table if line.startswith("Comparison of initial and final structures :"): table_begin=True if table_begin and line.startswith("------"): table_end=True …

Member Avatar for slate
0
263
Member Avatar for Ryan_8

I wouldn't pollute the main namespace with arbitrary variables. I provided this in comments. First you have to convert the input string into a dictionary. Then you can update some objects namespace with this dictionary. class Importedvalues(object): pass i=Importedvalues() vs='variable1=5&varible2=3&variable3=27&varible4=1' vs_modified=dict() for statement in vs.split("&"): varname,value=statement.split("=") vs_modified[varname]=value #locals().update(vs_modified) vars(i).update(vs_modified) print …

Member Avatar for snippsat
0
160
Member Avatar for RikTelner

Offtopic post, in the offtopic topic. As others pointed out, software is always part of larger system which involves interfaces to other softwares, people, and in the end the mother nature. In my opinion hacking is: Persuade a system to do something not normal, something out of ordinary, something not …

Member Avatar for Coloradojaguar
0
358
Member Avatar for Vish0203

Your function does what zip builtin function does. Just much more inefficiently. It takes iterables, and return a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The returned list is truncated in length to the length of the shortest …

Member Avatar for slate
0
188
Member Avatar for fheppell

You should put directories into the path variable. Python.exe is not a directory. http://docs.python.org/3.3/using/windows.html

Member Avatar for slate
0
354
Member Avatar for MrNoobieCoder

Well. I don't know where to begin. There is too much code. Seriously. Please consider not to repeat almost the same code for every difficulty. You can factor it out, and make the whole thing better. Like this: import random import time from collections import namedtuple def get_int(prompt=""): while True: …

Member Avatar for woooee
0
307
Member Avatar for ajit.nayak

Using csv does not help, because there isn't a single comma in the input. The first row in the output is: 11 hour, 38 min, 47 sec. So the seconds are: `11*60*60+38*60+47= 4197` How is 44700 calculated? What is that? Something like this: with open("conv.csv","w") as fo: with open("time.csv") as …

Member Avatar for slate
0
269
Member Avatar for aVar++
Member Avatar for Gribouillis
0
249
Member Avatar for laura301019

*How would I add the user username to the dictionary so that the username can be displayed on the logged in page?* You make session["username"]=username in checkLogin if login is successfull. However. This is not a session. Session is a set of dictionaries that is present for each user (anonym …

Member Avatar for slate
0
371
Member Avatar for DoomCarnage

If the user can guess infinitely, then an infinite loop (or infinite recursion) seems to be adequate. What is the expected operation of the program? The code seems to contain: * You have a one (?) character long Word * You ask the user to quess(guesschar). * If the quesschar …

Member Avatar for slate
0
120
Member Avatar for Tayler_1

Without knowing what the problem at hand is... The preferred way of reading a file line by line is: with open('filename.txt') as fp: for line in fp: print(line) Your code opens program0.4.txt, reads everything into a string. Then you split this string by space and enter. So your line variable …

Member Avatar for Tayler_1
0
1K
Member Avatar for glez_b

You define four dictionaries: sum_temperature day-> sum of temperature on the given day count_temperature day-> count of temerature data on given day likewise with moisture. You read in the file line by line. You parse one line into day, temerature, moisture. Time and precipitation is not needed for the task. …

Member Avatar for glez_b
0
3K
Member Avatar for 123pythonme

Check out [this.](http://www.daniweb.com/software-development/python/code/217082/eratosthenes-sieve) There are highly optimized codes there for generating prime numbers. Including my one :) They give you primes to 10**6 in seconds. If you post your code we can pinpoint, why is it so slow.

Member Avatar for vegaseat
0
262
Member Avatar for Hashim Javed

Oh, come on. Don't demand us to find out what the task is, then solve it. If you cannot answer your own question by using paper and pencil, then you cannot solve it in python either...

Member Avatar for vegaseat
0
294
Member Avatar for sophia_sin

You need to define what a star IS. Read [this](http://en.wikipedia.org/wiki/Star_polygon) Basically you have n points and you should make cyclic [arithmetical sequence](http://en.wikipedia.org/wiki/Arithmetic_progression) that contains all the points and have a difference more then 1 (in case of a square and triangle it can be 1). For example for a poligon …

Member Avatar for woooee
0
176
Member Avatar for slate

The most efficient static sieve generator in python I have seen so far. Returns the list of primes, that are not greater than n.

Member Avatar for vegaseat
1
496
Member Avatar for AcmeUK

I read the docs quickly. If I read it correcty, there is no advertised funkcionality in modemdriver.py, that allows you to use it as a library. As you said it. If all else fail you can construct the command line and the files needed in python, and run the whole …

Member Avatar for AcmeUK
0
237
Member Avatar for Waseemaburakia

Some remarks: You do not handle incorrect input. If this is your intention, then this is ok. The lines from 5-24 can be written: `smallest,bigest=min((f,s,t)), max((f,s,t))`

Member Avatar for slate
0
262
Member Avatar for talat.zaitoun

> 'm also a Python-starter. Question to the OP: What is the purpose of following function? > > def calculate_gpa(numbercourses): coursenumber = 1 > > It returns nothing; None I guess. > It does nothing with the parameter numbercourses. > It sets a variable(global?) coursenumber to 1. Yes it returns …

Member Avatar for slate
0
177
Member Avatar for mrgadgets
Member Avatar for slate
0
141
Member Avatar for Ismatus3

Please try to reformulate your question. Your program inserts something into a database. You can do anything after that... What is an "event"?

Member Avatar for Ismatus3
0
122
Member Avatar for goo_1

What is a counted file? Please provide a testcase. For example you can count newlines and characters like this: infilename = input("Enter the name of the file:") count_newlines=0 count_chars=0 with open (infilename ,'r') as infile: for line in infile: count_newlines+=1 count_chars+=len(line) print(count_newlines) print(count_chars)

Member Avatar for vegaseat
0
328
Member Avatar for rwe0

Try [selenium](http://docs.seleniumhq.org/) or [mechanize](https://pypi.python.org/pypi/mechanize/).

Member Avatar for rwe0
0
242
Member Avatar for chanchalrawat

You are very far from the solution. Maybe you should try a much easier task first. For example you have no working code. You create a wallet, a lock and a global variable and define two functions. You have a syntax error at line 4 because there is no right …

Member Avatar for Gribouillis
0
357
Member Avatar for bright.silva

First of all, if you have to return "set3" or similar, then you have to have it available as a data. My quick and dirty solution is below: from collections import defaultdict data={"set1":["01","34","29","16"], "set2":["45","88","19","17"], "set3":["56","21","57","20"], "set4":["29","42","89","08"], "set5":["19","45","56","20"], "set6":["85","56","33","78"]} positions=defaultdict(set) # which value, in which positions: which sets allvalues=set() # which …

Member Avatar for bright.silva
0
272
Member Avatar for varun mahawar

Create a html page, that contains what you want. Create a python program, that creates that html page for you as a string. Go to cherrypy [documentation.](http://docs.cherrypy.org/stable/concepts/basics.html). Instead of returning "Hello world", reaturn the html page, that you have previously created.

Member Avatar for TrustyTony
0
117
Member Avatar for Ravic85

Can you provide the expected output? What is a command variable? What is a dictionary level? What I understand is that the first two lines should be stored as: data={"B":( (128.9,"hello"), (1918.1,"hi"), (2938.2,"world"), ), "H":( (12.2,"India"), (218.6,"Lost"), (29.9,"Place"), ) }

Member Avatar for phorce
-1
220
Member Avatar for plasticfood

*Min function does not return an int.* Min function gets a sequence and returns the lowest element of that sequence. In that case this sequence is a list of (distance, coordinates) pairs. If you have a list of distance and coordinates like: [(12,(1,2)), (1,(12,25)), (0,(1525,13))] It will return the (0,(1525,13)) …

Member Avatar for plasticfood
0
396
Member Avatar for marethamogale

Your code has hardly anything to do with the task you mentioned in the first post. Try to program the following procedure in python. Let's make two variable that will store the number of tails and heads. Let they be: numtails=0, numheads=0 Loop begins here. Count 100 times. For each …

Member Avatar for phorce
0
176
Member Avatar for farmwife

You do not get this error when you iterate over the elements of a set. elements={1,2,3} for each in elements: print each You do not get this error when you convert a set to a list. `listelements=list(elements)` You **do** get this error, when you try to index a set: print …

Member Avatar for farmwife
0
7K
Member Avatar for giancan

What does restitution in that case mean? Can you give example input and output?

Member Avatar for giancan
0
347
Member Avatar for thecreator232

You mean, like [this](http://www.wikihow.com/Make-a-Web-Browser) ? :) To develop a webbrowser is as very complex task. Are you sure that this is the task? If yes, I advise you to learn from [others](http://w2spconf.com/2008/papers/s2p2.pdf). Google for webbrowser design.

Member Avatar for slate
0
468
Member Avatar for Reethu_1

If you remove the duplicates form the linked list: 3,2,8,8,8,5,2,3 then it remains: 3,2,8,5. I do not understand why you expect a list with duplicates. If the Node object is something like this: class Node(object): def __init__(self, value, next=None): self.next=next self.value=value Then removing the duplicates is something like this (the …

Member Avatar for TrustyTony
0
811
Member Avatar for sujan.dasmahapa

It works on windows. `python pro.py -u aaa -p Example$319` aaa Example$319 calling program The shell you are using is interpreting your arguments. Try to escape the arguments with apostrophes (depending on the shell you are using). Also the shebang (#!...) line should be int the first line.

Member Avatar for almostbob
0
4K
Member Avatar for dreking6

double underscore in init Several typos. class employee(): empcount=0 def __init__(self,name,salary): self.name=name self.salary=salary employee.empcount+=1 def displaycount(self): print 'Total employee: %d' %employee.empcount def displayemployee(self): print 'Name:',self.name,'salary:',self.salary ######################################################### #main program emp1n=raw_input('enter name of employee1:') emp2n=raw_input('enter name of employee2:') emp1s=input('enter salary of employee1:') emp2s=input('enter salary of employee2:') emp1=employee(emp1n,emp1s) emp2=employee(emp2n,emp2s) emp1.displayemployee() emp2.displayemployee() print 'total …

Member Avatar for dreking6
0
6K
Member Avatar for dustin.hunt1

In the sample text you provided there is no "|" charachter. You base your split on it. How and why? I would have written the program for you, if I had found the kjv.txt in the format you mentioned by quick googling. All I found was this: http://www.bibleprotector.com/TEXT-PCE.zip , which …

Member Avatar for slate
0
890
Member Avatar for mgold

In my experience this is one of a big issues with python. There is no methodology for design. No online resource about how to turn requirements into code skeleton. I think that is because there are rarely big projects (with more than 10 developer at a time), and the few …

Member Avatar for snippsat
0
178
Member Avatar for pythonforlife

Not a python question. In general a file is a stream of bytes. You merge two files by reading them one after the another and writing them. fo=open("outfile","wb") fo.write(open("infile1").read()) fo.write(open("infile2").read()) fo.close() Thats the general part of it. However a file is interpreted by a program. A videofile is interpreted by …

Member Avatar for rudasi
0
5K
Member Avatar for stealthless

"EOF" means three letters: E,O,F. This statement is never True: if textInput == "\n" and textInput == "EOF": One way to handle this ("\n" cannot be entered) is to catch EOFError: inputs=list() while True: try: s = input() inputs.append(s) except EOFError: print(inputs) break

Member Avatar for slate
0
543
Member Avatar for Mohammad_7

Maybe you have more python binaries installed. Instead of virtualenv thing use /usr/bin/python2.6 PATH/TO/VIRTUALENV thing Also: http://stackoverflow.com/questions/5904319/problem-with-virtualenv-in-mac-os-x

Member Avatar for slate
0
296
Member Avatar for stealthless

Errors: You define user_inputs as a list, then redefine it as a string. You might have not decided whether you collect all the inputs and then calculate the sum, or you want to calculate it on the fly.. Wrong intendation in the post. You do not use the total variable. …

Member Avatar for slate
0
186
Member Avatar for ihatehippies

I have once watched a great pycon video about the python execution process. Sadly I cannot find any written words about that. In my understanding it works as follows: * The python interpreter "executes" from the first line of the script. * This execution involves compilation and evaluation. Evaluation is …

Member Avatar for james.lu.75491856
0
809
Member Avatar for pythonforlife

- The line: segment = f.read(segmentbytes) should be in the "for j in range(numframe)" loop. - Your numframe is not correct. Shoult be +1.

Member Avatar for pythonforlife
0
136

The End.