On 25 May 2013 14:42, Ken G. wrote:
> May I suggest that instead of:
> how about:
>
> flips = heads = tails = 0
>
> Ken
How about flips = heads = 0
tails can then be calculated from flips - heads.
--
best regards,
Robert S.
___
Tutor maillist - Tutor@
On 25 May 2013 04:19, Steven D'Aprano wrote:
> You can edit *other* people's questions and answers??!??!??
>
> What. The. Hell.
Yes; I think that the idea is that it allows people to fix spelling
errors and/or reference mistakes, or maybe add things to clarify
something that the answer glossed ov
> I'm working through the Book Python Programming for the Absolute Beginner and
> am wondering if you could help me out with the coding to certain
> Challenges at the end of the book, specifically chapter 7 challenges 1 and 2
> and chapter 8 challenges 1 and 3.
Since I personally don't have that
Hi again, Tutor List.
I am trying to figure out a problem I've run into. Let me first say
that this is an assignment, so please don't give me any answers, but
just nudge me in the general direction. So the task is this: from a
text file, populate three different dictionaries with various
informati
On 25 March 2013 01:13, Mandi Seger wrote:
> Hello, everyone,
>
> I am looking for suggestions on a beginner's book for learning Python. I
> have a nursing background with basic science and math education. I have no
> programming experience in any computer language.
Head First Python or Head Firs
> As I said, I don't really understand why a roulette outcome has a name in
> the first place, but given that it does, I don't any problem with comparing
> the names directly. Still, I would probably write it as an __eq__ method,
> since it's easier to write a == b than a.name == b.name.
I figured
Hi list. I'll preface this by saying that I am very grateful for all
of you, and thank you in advance to anyone that answers.
I'm currently working on a roulette simulator, because it seemed like
fun. I found out I needed a way to compare two different outcomes, and
it was suggested to me that I s
>> 3. Are there defined procedures for doing the required processing?
>
> If you meant conversion functions, int() and float() are examples of
> those. You of course (most of the times) have to make use of string
> manipulation functions (strip(), rstrip(), etc) to extract the exact
> data item yo
On Mar 20, 2013 10:49 p.m., "xDog Walker" wrote:
>
> On Wednesday 2013 March 20 13:39, Robert Sjoblom wrote:
> > A word of advice: next is a keyword in python
>
> ~/Packages/Python/Notable-0.1.5b> python
> Python 2.5 (r25:51908, May 25 2007, 16:14:04)
> [
> Hello, I am a beginning python student and I am having trouble with a
> program I am writing.
Hello, and welcome. Since you don't say if this is an assignment or
not, I will just point you in the right direction, and point out a few
things you might make use of.
> def B1():
> period = "."
You
On 16 March 2013 05:08, Vincent Balmori wrote:
> I am trying to loop a simple exception. I tried to put a while loop, but I
> keep getting syntax issues. I also tried to alternatively use something on
> the lines of "while number != int" also with no avail.
It would help if you:
a) didn't send HTM
> What is the correct syntax to covert English characters from uppercase to
> lowercase and from lowercase to uppercase?
>
s.upper() and s.lower()
--
best regards,
Robert S.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription
> Finally, from a user experience point of view, it might be more logical to
> make the keys w,a,s,z North, West,East and South respectively since its a
> more logical correspondence to the compass points (assuming a standard
> QWERTY keyboard layout).
Most games use WASD, so user experience would
>> Umm. No. Sorry, Mark, but that site and the core-mentorship list it
>> advertises are intended for progammers who want to be helped in the
>> development *of* Python, not development *in* Python. Ie, otherwise
>> experienced programmers who are unfamiliar with the Python codebase.
>>
>> TJG
>>
>
> I am fairly sure i am querying the FRED API, but i am unsure how to
> _access and use_ the dict objects that it is returning. For example,
> how would i just print out values?
If it's a dict object, the standard dictionary behavior and methods
should work. I've not looked closely at the FRED API
> I would like to validate data attributes before the object is instantiated
> or any changes thereafter. For example, following is a simple Person class
> with name and age attributes. [snip] Following is my
> example code:
> class Person(object):
> def __init__(self,name,age):
> self.name
> Could the experts, please, recommend a beginner's book to learn the
> principles of good programming?
I don't know about expert, but I found the Head First Lab's approach
to be really good. The Python book is structured like so:
-Lists introduction
-(PyPi)/creating modules -- this I hope has bee
>> i sort of heard about a stack its a C/C++ thing i think?
>
> A stack is fundamental to modern programming languages. The only two
> machines I've used that didn't have a stack implemented at the machine level
> were the CDC 6000 series, and the IBM 360. Both products of the 60's.
A while back
On Jan 3, 2013 2:22 a.m., "Conor Grevlos" wrote:
>
> I downloaded the python source folder, with chapters 1 through 12 I
think. But it just opens up the program that is already built, not one that
shows me the code.
Open the files in an editor of your choice, don't run them.
_
>> I am currently thinking about "Invent Your Own Computer Games with
>> Python" by Al Sweigart.
[snip]
>> Has anyone experience using this book?
"Snake wrangling for kids" is pretty good for teaching Python; it's
also free (which is a bonus):
http://www.briggs.net.nz/snake-wrangling-for-kids.html
> What's "who and whos"?
They're matlab functions:
who lists the variables currently in the workspace.
whos lists the current variables and their sizes and types. It also
reports the totals for sizes.
--
best regards,
Robert S.
___
Tutor maillist - Tu
On 30 April 2012 23:25, Comer Duncan wrote:
> Hi,
>
> I have a newbie type question. Say I have started a python (or
> ipython) session and have done some imports and have also defined some
> new variables since the session started. So, I have in my current
> namespace a bunch of things. Suppose
> I can't figure out
> 1) How to remove "y" from the list and continue the loop; when I use .remove
> etc. it runs once then give me the error that "y" is not in the list.
>
> I imagine the answer is quite simple I'm just getting really frustrated
> trying to get this done any advice is appreciated
> You haven't shown us the critical part: how are you getting the lines in
> the first place?
Ah, yes --
with open(address, "r", encoding="cp1252") as instream:
for line in instream:
> (Also, you shouldn't shadow built-ins like list as you do above, unless
> you know what you are doing. If yo
I'm sorry if the subject is vague, but I can't really explain it very
well. I've been away from programming for a while now (I got a
daughter and a year after that a son, so I've been busy with family
matters). As such, my skills are definitely rusty.
In the file I'm parsing, I'm looking for speci
> You can "solve" the problem by pretending the input file is also cp932 when
> you open it. That way you'll get the wrong characters, but no errors.
So I tried that:
Traceback (most recent call last):
File "C:\Users\Azaz\Desktop\CK2 Map Painter\Parser\test parser.py",
line 6, in
text = alph
Okay, so here's a fun one. Since I'm on a japanese locale my native
encoding is cp932. I was thinking of writing a parser for a bunch of
text files, but I stumbled on even printing the contents due to ...
something. I don't know what encoding the text file uses, which isn't
helping my case either (
> Hi,
> I have been hearing this refactoring of code. Well does it have
> any thing like this in Python and if it is then what is it all about.
> Thanks.
> Regards,
> Ejaj
Refactoring is just a way of restructuring code. It can be breaking
code apart to more logical pieces -- moving parts of a
>> I'd appreciate any feedback on this and good tutorials or books on
>> Python 3 and the IDEs suggested. There are many available and I'm
>> wondering what you as users find effective.
I fiddled a bit with the Eric Python IDE; Eric5 for Python3 and Eric4
for Python2; overall I'd say that Eclipse
> import random #import random number generator module
> target = random.randint(1,100) #generates random number between 1 and 100
> guess = float(raw_input('pick a number between 1 and 100'))
> while guess != target:
> if guess < target: print 'too low'
> elif guess > target: print 'too high
> I am having some trouble understanding how to use __name__== '__main__'. Can
> you please give me some insight?
if __name__ == '__main__': allows you to specify code that will only
be run if you run the actual script it's in; anything in the if block
won't be run if you import the module.
>Also
>> class Card(object):
>> def __init__(self):
>> self.score = self.deal()
>>
>> def deal(self):
>> """deal a card from 1 to 52 and return it's points"""
>> return self.getValue(int(math.floor(random.uniform(1,
>> 52
>
> I think you only
On 5 January 2012 19:41, Joaquim Santos wrote:
> Hi List!
[...]
> This is my script (I know that I only verify a small range but it
> works for what I want for now...)
>
> import string
>
> def decrypt(cypheredText, shiftedCypherNumber):
> '''
> This function will take two arguments. The first
On 3 January 2012 16:21, Joel Goldstick wrote:
> --
Joel, when you start your emails with this (two dashes) some email
readers (gmail among them) will think you're ending your email; I have
to expand your post because it thinks that what is hidden is the
signature. Just thought you should know.
> Some improvements to think about, in order of least secure (easiest) to most
> secure (hardest).
>
> (1) "my secret password.txt" is a crappy name. Is there a better name?
I'm going to go with "EULA.txt"; the reasons should be obvious.
--
best regards,
Robert S.
___
On 15 December 2011 23:37, Calle wrote:
> -Ursprungligt meddelande- From: Robert Sjoblom
> Sent: Thursday, December 15, 2011 10:34 PM
> To: Calle
> Cc: tutor@python.org
> Subject: Re: [Tutor] [TUTOR]Code Deciphering
>
>
>> I was wondering, how do you use Python
> I was wondering, how do you use Python to decipher codes? It feels like it
> should be pretty simple, but I haven't found any tutorials about it yet.
What kind of codes? Or do you mean ciphers? Generally speaking, a code
represent letters or numbers in transmitting a message. In other
words, a c
So, it turns out that my ISP blocked Project Euler, so instead of
working on my next problem, I polished Problem 4 a bit:
>A palindromic number reads the same both ways. The largest palindrome made
>from the product of two 2-digit numbers is 9009 = 91 × 99.
>Find the largest palindrome made from
surya k wrote:
> This is a project Euler puzzle. http://projecteuler.net/problem=30
> I applied brute force way and here is my codek=0for p in range(1,10):
> for q in range(0,10): for r in range(0,10):
>for s in range(0,10):
On 12 December 2011 11:59, Bulent Arikan wrote:
> Thank you Dax! That was it! Now I can run the script.
>
> Cheers,
> Bulent
You don't have to submit the entire digest when you're replying; trim
it down to what you're actually replying to. Also, please avoid
posting your reply on top -- it makes
> There are other approaches that may bear looking at, like the SciPy library.
> But first we'd need to know just what you need with this factorial.
Wouldn't a prime swing implementation be the absolutely fastest?
Something like this:
http://en.literateprograms.org/Special:Downloadcode/Factorials
I had a situation where there were 300+ files needed to be renamed to
standardized naming; the problem was that each group that had worked
on the project had their own naming convention and group tag. One
group had date_number_subnumber_grouptag where others might have
grouptag_date_number_subnumbe
> So you can roughly double the speed of your function by skipping even
> numbers other than two. Remember that 2 itself is prime, but any other
> multiple of 2 is not. Take that test outside of the loop, and then loop over
> every second number starting with 3.
>
So, if I understood this right, m
> from math import sqrt
>
> def isprime(n, factor):
> if n == 1:
> return False
> for x in range(2, round(sqrt(n))):
Ooops, this should obviously read
for x in range(factor, round(sqrt(n))):
best regards,
Robert S.
___
Tutor maillist - Tut
> Well, there are really only a couple of optimizations that you could make.
> That's the nice (bad?) thing about primes - you really only *can* brute
> force a solution. That's why nice things like encryption exist.
Yes, I know that; perhaps I was unclear but my issues with brute force
are for sol
So I've recently started poking at the Project Euler site, because I
feel that I need to practice writing code. For those of you interested
in solving the problems on your own I advice you to not read this, as
it will spoil the solution.
Problem 3 is this:
The prime factors of 13195 are 5, 7, 13 a
On 12 November 2011 07:27, wrote:
> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-r
> print random.randrange(1,42)
> If you want to collect the intermediate results, either store them in a
> list:
>
> results = []
> for i in range(6):
> results.append(random.randrange(1,42))
Gmail has removed the "Reply All" function for some ABSOLUTELY
RIDICULOUS REASON, so I think peopl
>> hello all,
>> anyone know how i would go about printing 6 random numbers, i know i could
>> copy and paste 6 times (which would work) but i was thinking about a while
>> loop, ie. while lottery_numbers.count is <7.
>> Is it possible to code this? is it possible to count random variables? i am
> Subject: [Tutor] Running a loop
> I am using Windows 7 and python 3.1. This is a block from a slot machine
> code. It takes the random generated words and indicates if it wins or loses.
> I can't figure out why it wants to print the last print statement 'Loser' no
> matter if the elif statements
> shantanoo, Andre, and Robert:
>
> All of your solutions seem to work (and thank you for the tips!), however,
> with each solution there seems to be 2 MACs that should not be in the
> results.
>
> 00:1C:14:BA:D9:E9 and
> 00:16:3E:EB:04:D9
>
> should not be be turning up in the results because they
> Scenario: I have a list of MAC addresses that are known and good, and am
> comparing it to a list of MACs found in a scan. I want to weed out the
> those which are unknown. I am using IDLE (Python 2.7) on Windows, and all
> files are in the same directory.
>
> Code:
>
> scanResults = open('scan
>> #assuming target number 15
>> roll = (result, initial_mins, initial_max)
> I'd forget the tuple and just use the names,
> it is more readable that way...
>if result > 15:
>if initial_mins >= 2:...
>elif initial_max >=2:...
> But otherwise it seems to reflect the rules as you've writte
I've written a function that rolls (standard) dice. There are a few
special cases though:
Any sixes rolled are removed and 2*number of sixes new dice are rolled
in their place.
Initial roll is important to keep track of.
I've solved it with the following function:
from random import randint
def
>> Are you using Python 3 and urllib, and not using httplib2? Because I
>> honestly can't get urllib.request.urlopen to work with
>> http://www.boursorama.com/ -- I only get b'' from there.
>
> Yes, Python 3.2 which version one are you using? I tried both with
> debug and without.
Python 3.2.1 64
>Don't know, works fine for me..
>
>Greets
>Sander
Are you using Python 3 and urllib, and not using httplib2? Because I
honestly can't get urllib.request.urlopen to work with
http://www.boursorama.com/ -- I only get b'' from there.
best regards,
Robert S.
_
So, an issue regarding urllib (python 3) came up earlier. I solved it
by using httplib2 instead, but I'm rather curious as to why urllib
wouldn't work.
Here's the code I'm working with:
from http.client import HTTPConnection
HTTPConnection.debuglevel = 1
from urllib.request import urlopen
url =
> Can someone please explain the difference between methods and functions?
I've heard the explanation "A cow is an animal but an animal is not
necessarily a cow." used to describe the difference between methods
and functions (ie, all methods are functions, but not all functions
are methods). Obviou
> I have tried to follow the tutorial I found here:
>
> Python 2.7 Tutorial
> http://www.youtube.com/watch?v=uh6AdDX7K7U
>
> This is what I have done so far:
>
> #!/usr/bin/python
>
> from Tkinter import *
> import Tkinter.MessageBox
I figured I might as well, given how I recently had to learn abo
> I think you are on the right track: Python 3.2's input() has a nasty bug on
> Windows (http://bugs.python.org/issue11272). If you repeat the following in
> your interactive interpreter (invoked from the commmandline)
>
input()
> 123
> '123'
>
> and see '123\r' instead of just '123' you are a
> Robert Sjoblom wrote:
>> I have a quite odd problem, and I've come across it before but
>> probably ignored it at the time because I had other concerns. I've
>> tried googling for the answer but haven't really come closer to
>> solving it.
>> This
I have a quite odd problem, and I've come across it before but
probably ignored it at the time because I had other concerns. I've
tried googling for the answer but haven't really come closer to
solving it.
This is what happens:
C:\[path]\nester>C:\Python32\python.ex
e setup.py register
running regi
>> * Or you just get used to the fact that some numbers are not exact in
>> floating point.
>
> This got me thinking. How many decimal places do you need to
> accurately, say, aim a laser somewhere in a 180 degree arc accurately
> enough to hit a dime on the surface of the moon?
>
> Alan
In short:
On 2 June 2011 22:50, Brett Ritter wrote:
> On Thu, Jun 2, 2011 at 4:06 PM, Robert Sjoblom
> wrote:
>> Python already has the urllib/urllib2 package that automatically
>> follow redirects, so I don't see why you'd need a 3rd-party module to
>> deal with it? Wh
> When you hit the page and you get an HTTP redirect code back (say,
> 302), you will need to make another call to the URL specified in the
> "Location" parameter in the response headers. Then you retrieve that
> new page and you can check you got an acceptable HTTP response code
> (such as 200) an
> That's pretty much all you need to know to start using objects. There's
> a lot more though: inheritance, class methods and static methods (as
> opposed to ordinary methods), properties, descriptors (advanced!),
> slots, and more. But one step at a time.
>
> Any questions, don't hesitate to ask!
-- Hugo Arts wrote --
>Why are you asking for the user to enter a key? you're iterating over
>all keys in the dictionary, so there's no need to ask the user for
>keys, you already know them. Why not do this:
>b = int(input("Enter value for key %s: " % key))
>dictionary[key] = b
I have a great an
Hi again, list! A quick question about dictionary behaviour. I have a
dictionary of keys, and the user should be able to enter values into
said dictionary. My idea was this:
def addData(key, value):
dictionary[key] += int(value)
return None
dictionary = {"a":0, "b":0, "c":0, "d":0}
for k
68 matches
Mail list logo