[Tutor] step value

2011-06-13 Thread Vincent Balmori
I am stuck on a question for Absolute Beginner's. I googled this and there have 
been others who have not understood the question and I am also not clear on the 
question he is asking. This function is a part of a tic tac toe 
program."Improve 
the function ask_number() so that the function can be called with a step value. 
Make the default value of step 1."



def ask_number(question, low, high):
"""Ask for a number within a range."""
response = None
while response not in range(low, high):
response = int(input(question))
return response___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python-gobject for debian4

2011-06-13 Thread Ganesh Kumar
Hi Guys.

I want python-gobject package for debian4 (etch). But unfortunately
removed for debian4 depository .

How to install python-gobject package in debian4..

My Idea is

download debian5 repository python-gobject.deb file
Install in debian4.

I have try is working fine.

but the thing is reboot the mache show kernel-panic (KERNEL TO OLD)

I search google..its libc6 problem.. But i want python-gobject
otherwise my project not working ..

How to migrate python-gobject for debian4
please guide me..


-Ganesh.


Did I learn something today? If not, I wasted it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] step value

2011-06-13 Thread Steven D'Aprano

Vincent Balmori wrote:
I am stuck on a question for Absolute Beginner's. I googled this and there have 
been others who have not understood the question and I am also not clear on the 
question he is asking. This function is a part of a tic tac toe program."Improve 
the function ask_number() so that the function can be called with a step value. 
Make the default value of step 1."


It's hard to guess what the author was thinking if he doesn't explain 
it, but I think what he means is this:


The aim of the "ask_number" function is to get the caller -- you -- to 
enter a number in the range(low, high). That much is easy, and you 
already have the function doing that.


But the range function can take a third, optional argument "step". 
Instead of (for example)


range(1, 20) => [1, 2, 3, 4, 5, 6, ... 17, 18, 19]

you can pass a step N and get only every Nth value, e.g.:

range(1, 20, 3) => [1, 4, 7, 10, 13, 16, 19]  # every third number


So, you have a function which calls range() internally:



def ask_number(question, low, high):
"""Ask for a number within a range."""
response = None
while response not in range(low, high):
response = int(input(question))
return response


and your mission is to modify that function so that it takes an optional 
argument that defaults to 1, and passes that argument to the range() 
function as step.



Does that help?




--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python-gobject for debian4

2011-06-13 Thread Steven D'Aprano

Ganesh Kumar wrote:

Hi Guys.

I want python-gobject package for debian4 (etch). But unfortunately
removed for debian4 depository .


This is not a Python problem. It is especially not a problem about 
learning Python.


You should ask this at either a Debian forum or on the python-gobject 
mailing list (if any) or ask the maintainer of python-gobject.




--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Nathan
who can tell me how to unsubscribe the message.




At 2011-06-13 01:13:05,"Steven DAprano"  wrote:

>Ryan Strunk wrote:
>> Hi everyone,
>> I'm designing a timeline. When the user presses the right arrow, 0.1 is
>> added to the current position. The user can add events to the timeline, and
>> can later scroll back across those events to see what they are. But
>> something I absolutely don't understand is happening:
>> I used the program to place events at 1.1, 2.1, and 3.1. Here is the end of
>> the debug output for arrowing to 3.1 and placing the event:
>> position = 2.7
>> position = 2.8
>> position = 2.9
>> position = 3.0
>> position = 3.1
>> event placed.
>> Everything appears straight forward. 
>
>
>It only *appears* straight forward, it actually isn't. That's because 
>the printed output is rounded so as to look nice. Compare:
>
> >>> x = 1/10.0
> >>> print(x)  # displayed as nicely as possible
>0.1
> >>> print('%.25f' % x)  # display 25 decimal places
>0.155511151
>
>
>For speed and simplicity, floats are stored by the computer using 
>fractional powers of two. That's fine for numbers which are powers of 
>two (1/2, 1/4, 1/256, and sums of such) but numbers that humans like to 
>use tend to be powers of 10, not 2.
>
>Unfortunately, many common fractions cannot be written exactly in 
>binary. You're probably familiar with the fact that fractions like 1/3 
>cannot be written exactly in decimal:
>
>1/3 = 0.... goes on forever
>
>The same is true for some numbers in binary:
>
>1/10 in decimal = 1/16 + 1/32 + 1/256 + ...
>
>also goes on forever. Written in fractional bits:
>
>1/10 decimal = 0.00011001100110011... in binary
>
>Since floats can only store a finite number of bits, 1/10 cannot be 
>stored exactly. It turns out that the number stored is a tiny bit larger 
>than 1/10:
>
> >>> Fraction.from_float(0.1) - Fraction(1)/10
>Fraction(1, 180143985094819840)
>
>Rounding doesn't help: 0.1 is already rounded as close to 1/10 as it can 
>possibly get.
>
>Now, when you print the dictionary containing those floats, Python 
>displays (almost) the full precision:
>
> >>> print {1: 0.1}
>{1: 0.10001}
>
>
>In newer versions of Python, it may do a nicer job of printing the float 
>so that the true value is hidden. E.g. in Python 3.1 I see:
>
>
> >>> print({1: 0.1})
>{1: 0.1}
>
>but don't be fooled: Python's print display is pulling the wool over 
>your eyes, the actual value is closer to 0.10001.
>
>
>One consequence of that is that adding 0.1 ten times does not give 1 
>exactly, but slightly less than 1:
>
> >>> x = 0.1
> >>> 1 - sum([x]*10)
>1.1102230246251565e-16
>
>
>(P.S. this is why you should never use floats for currency. All those 
>missing and excess fractions of a cent add up to real money.)
>
>
>To avoid this, you can:
>
>
>* Upgrade to a newer version of Python that lies to you more often, so 
>that you can go on living in blissful ignorance (until such time as you 
>run into a more serious problem with floats);
>
>* Use the fraction module, or the decimal module, but they are slower 
>than floats; or
>
>* Instead of counting your timeline in increments of 0.1, scale 
>everything by 10 so the increment is 1.
>
>That is, instead of:
>
>2.0  2.1  2.2  2.3 ...
>
>you will have
>
>20  21  22  23  24  ...
>
>
>* Or you just get used to the fact that some numbers are not exact in 
>floating point.
>
>
>
>
>-- 
>Steven
>
>___
>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] Floating Point Craziness

2011-06-13 Thread Alan Gauld


"Nathan"  wrote

Every message tells you:



who can tell me how to unsubscribe the message.




___
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




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Válas Péter
2011/6/12 Brett Ritter 

>
> Okay fine, so "1024" stored as a number only requires 10 bits (binary
> digits) to store,

Actually, 11. :-)

Another point that was still not emphasized enough: that's why Python's
documentation at
http://docs.python.org/dev/library/stdtypes.html#mapping-types-dict says:
"Note however, that since computers store floating-point numbers as
approximations it is usually unwise to use them as dictionary keys."
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Steven D'Aprano

Nathan wrote:

who can tell me how to unsubscribe the message.


Look at the bottom of every single message to the mailing list, and you 
will see this:



Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Steven D'Aprano

Válas Péter wrote:

2011/6/12 Brett Ritter 


Okay fine, so "1024" stored as a number only requires 10 bits (binary
digits) to store,


Actually, 11. :-)


I see your smiley, but actually more than that. Due to the way computers 
are designed, numbers are stored in fixed bundles of 8 bits making a 
byte. A single byte (8 bits) can store between 0 and 255. So to store 
1024, you need two bytes, or 16 bits, not 11.


In practice, that will usually be four bytes, 32 bits, or even eight.

And if you're using Python, where everything is an object, it will 
actually be fourteen bytes, or 112 bits:


>>> sys.getsizeof(1024)
14




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Válas Péter
2011/6/13 Steven D'Aprano 

> Okay fine, so "1024" stored as a number only requires 10 bits (binary
>>> digits) to store,
>>>
>>
>> Actually, 11. :-)
>>
>
>
> I see your smiley, but actually more than that.

OK, this was the math, I just told that 10 bits were not enough for 2^10.


>
> And if you're using Python, where everything is an object, it will actually
> be fourteen bytes, or 112 bits:
>
Where is the structure of this object (or Python objects in general)
documented?
Suppose, I would like to turn an object into a bytearray to study its
anatomy. But the converter wants to have an encoding as parameter. How can I
do that?

Péter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Medical Decision-Making Question

2011-06-13 Thread Fred G
Hello--

I'm a pre-med student interested in decision-making as applied to medical
decisions.  I am trying to build a medical decision-making algorithm and am
pretty stuck on a few things.

I've built a file that contains a list of many diseases and their associated
symptoms.  For example, here are the column headers and two sample rows (the
"|" = "or"):
DiseaseSymptoms
Cold
sore_throat|runny_nose|congestion|cough|aches|slight_fever
Flu
sore_throat|fever|headache|muscle_aches|soreness|congestion|cough|returning_fever

My questions are the following:
a)  How's the best way to make it so I can have a user type in a list of
symptoms and then have the computer tell the user the possible diseases that
share those symptoms? In other words, on a high-level I have a pretty good
idea of what I want my algorithm to do-- but I need help implementing the
basic version first.  I'd like to do the following:
>>>Please enter a list of symptoms
>>>[user_input]
>>>Possible diseases include: x, y, z

b)Once I get that working, could anyone point me to good code already
written in Python such that I could have a model (for syntax and overall
structure) for figuring out how to make the computer evaluate more factors
such as: patient age, patient history, and even downloading archival data
for patients in the same demographic group?

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Medical Decision-Making Question

2011-06-13 Thread James Reynolds
I would start by getting a lot of the parameters you need in a database such
as SQLite (comes with python).

So for example, you would have a disease with known symptoms. You could
structure your tables with diseases symptoms

So, say the disease is a cold in the table you will have a row for cold and
columns identifying each symptom (by unique IDs).

In your symptom table you would have a row for each symptom and a column for
its parameters and probabilities and such.  For example, gender exclusive,
age exclusive, geographic exclusive, workplace, etc.

>From there you can build your select statements on the fly using python's
string formating.

That's how i would do it anyway.

I'm sure there are other ways as well.

On Mon, Jun 13, 2011 at 10:22 AM, Fred G  wrote:

> Hello--
>
> I'm a pre-med student interested in decision-making as applied to medical
> decisions.  I am trying to build a medical decision-making algorithm and am
> pretty stuck on a few things.
>
> I've built a file that contains a list of many diseases and their
> associated symptoms.  For example, here are the column headers and two
> sample rows (the "|" = "or"):
> DiseaseSymptoms
> Cold
> sore_throat|runny_nose|congestion|cough|aches|slight_fever
> Flu
> sore_throat|fever|headache|muscle_aches|soreness|congestion|cough|returning_fever
>
> My questions are the following:
> a)  How's the best way to make it so I can have a user type in a list of
> symptoms and then have the computer tell the user the possible diseases that
> share those symptoms? In other words, on a high-level I have a pretty good
> idea of what I want my algorithm to do-- but I need help implementing the
> basic version first.  I'd like to do the following:
> >>>Please enter a list of symptoms
> >>>[user_input]
> >>>Possible diseases include: x, y, z
>
> b)Once I get that working, could anyone point me to good code already
> written in Python such that I could have a model (for syntax and overall
> structure) for figuring out how to make the computer evaluate more factors
> such as: patient age, patient history, and even downloading archival data
> for patients in the same demographic group?
>
> Thanks!
>
>
>
> ___
> 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] Medical Decision-Making Question

2011-06-13 Thread Jim Richardson
On Mon, Jun 13, 2011 at 7:22 AM, Fred G  wrote:
> Hello--
> I'm a pre-med student interested in decision-making as applied to medical
> decisions.  I am trying to build a medical decision-making algorithm and am
> pretty stuck on a few things.
> I've built a file that contains a list of many diseases and their associated
> symptoms.  For example, here are the column headers and two sample rows (the
> "|" = "or"):
> Disease                Symptoms
> Cold
> sore_throat|runny_nose|congestion|cough|aches|slight_fever
> Flu
> sore_throat|fever|headache|muscle_aches|soreness|congestion|cough|returning_fever
> My questions are the following:
> a)  How's the best way to make it so I can have a user type in a list of
> symptoms and then have the computer tell the user the possible diseases that
> share those symptoms? In other words, on a high-level I have a pretty good
> idea of what I want my algorithm to do-- but I need help implementing the
> basic version first.  I'd like to do the following:
Please enter a list of symptoms
[user_input]
Possible diseases include: x, y, z
> b)Once I get that working, could anyone point me to good code already
> written in Python such that I could have a model (for syntax and overall
> structure) for figuring out how to make the computer evaluate more factors
> such as: patient age, patient history, and even downloading archival data
> for patients in the same demographic group?
> Thanks!
>
>



One problem with writing the symptoms is misspelling and word choice,
is mild fever the same as slight fever? etc.

Another way to do that is to present a list, when the user selects one
item in that list, (say, fever, mild) the list is restructured to
exclude symptoms that would clash with that, like all the other
fevers.  After a while of clicking on list items, the evaluator can
make a best match against diseases.  Downside is a fair amount of
processing.

You could also group symptoms and have severity as a seperate, so you
select fever, then mild,high, whatever.

Evaluating it is going to be fun, it's a lot more than binary matches.



-- 
http://neon-buddha.net
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Medical Decision-Making Question

2011-06-13 Thread Steven D'Aprano

Fred G wrote:

Hello--

I'm a pre-med student interested in decision-making as applied to medical
decisions.  I am trying to build a medical decision-making algorithm and am
pretty stuck on a few things.



Essentially what you want is to build an expert system. I don't want to 
discourage you, but expert systems are big, complicated pieces of 
software! They're a form of artificial intelligence. You probably want 
to think hard about how to narrow the problem you're trying to solve.


You could google on "python expert system ai" are similar terms, see 
what comes up. Other search terms might include "inference engine": you 
want the software to *infer* a disease from a set of symptoms.


Another possibility is to look at "logic programming". Traditionally 
people do that in Prolog, but there are some tools for doing this in 
Python. Google on "prolog python", or look at Pyke:


http://pyke.sourceforge.net/


More comments below.




I've built a file that contains a list of many diseases and their associated
symptoms.  For example, here are the column headers and two sample rows (the
"|" = "or"):
DiseaseSymptoms
Cold
sore_throat|runny_nose|congestion|cough|aches|slight_fever
Flu
sore_throat|fever|headache|muscle_aches|soreness|congestion|cough|returning_fever

My questions are the following:
a)  How's the best way to make it so I can have a user type in a list of
symptoms and then have the computer tell the user the possible diseases that
share those symptoms? In other words, on a high-level I have a pretty good
idea of what I want my algorithm to do-- but I need help implementing the
basic version first.  I'd like to do the following:

Please enter a list of symptoms
[user_input]
Possible diseases include: x, y, z




First you need to decide, how would *you* decide which diseases are 
possible?


My *guess* is that you would do something like this:

for each symptom given:
for each disease:
if the symptom appears in the disease,
then add disease to the list of possible diseases


But should some symptoms count as stronger than others? I don't know.

Here is a toy example, presented without explanation because it's 1:50am 
here in Australia and I'm getting tired. I don't know whether you are a 
beginner at Python or you've been programming for years, so don't 
hesitate to ask if you don't understand any of it!



# Untested!

class Disease:
def __init__(self, name, symptoms):
self.name = name
self.symptoms = symptoms


known_diseases = [
  Disease('cold', set(
"sore throat|runny nose|congestion|cough|aches".split("|"))
),
  Disease('flu', set(
"fever|headache|muscle aches|returning fever".split("|"))
),
  Disease('ebola', set(
"tiredness|death|bruising over 90% of body|black blood".split("|"))
),
  ]


# note: for Python 2, use "raw_input" instead of input
symptoms = input("Please enter symptoms separated by commas: ")
symptoms = symptoms.lower()
symptoms = symptoms.split(",")

possible = []
for symptom in symptoms:
for disease in known_diseases:
if symptom in disease.symptoms:
possible.append(disease.name)

if possible:
print("You may have these diseases:")
print(*possible)
else:
print("Good news! You're going to have a disease named after you!")



Obviously in a real project, you would read the diseases from a file, or 
store them in a database.




b)Once I get that working, could anyone point me to good code already
written in Python such that I could have a model (for syntax and overall
structure) for figuring out how to make the computer evaluate more factors
such as: patient age, patient history, and even downloading archival data
for patients in the same demographic group?



Well, I must say you're certainly ambitious! This is a *hard problem*, 
which is why expert systems usually cost a lot of money.


Start by writing down how a human doctor would combine these pieces of 
information. Think about whether there are "anti-indicators", e.g. "if 
the patient doesn't have spots, it can't be measles!" (or maybe it can, 
I'm not a doctor...).


Age, history, demographics, etc. can be treated just like symptoms. "If 
the patient is male, he can't be pregnant." (Although there are such 
things as false pregnancies, and even men can get that!)


My guess is that doctors will first try to think of all the diseases it 
could be, and then eliminate those it can't be, and then take a 
probabilistic estimate (i.e. a guess) from those left over. E.g.:


If the patient has the symptoms of ebola, and has been to Africa in the 
last month, or works with monkeys or in germ warfare, then the chances 
of ebola are 95%; otherwise the chances of ebola are 1%.


Google on Bayesian probability and Bayes Theorem.

Also look at fuzzy logic. That's another good approach for expert system 
problem solving.


The problem you are likely to face is not that there's no good way to 
decide which diseases are li

[Tutor] Floating point exercise 3 from Learn python the hard way

2011-06-13 Thread amt
Hello, I am a python beginner currently learning from "Learn python the hard
way". I'm stuck at exercise 3 and I would like if it's possible to get some
help so I can move on.
Here is the source code:

1 print "I will now count my chickens:"
2 print "Hens", 25 + 30 /6
3 print "Roosters", 100 - 25 * 3 % 4 #Output is 97
4 print "Now I will count the eggs:"
5 print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6 #Output needs to be 6,83 but
Python give me 7
6 print "Is it true that 3 + 2 < 5 - 7? "
7 print 3 + 2 < 5 - 7
8 print "What is 3 + 2?", 3 + 2
9 print "What is 5 - 7?", 5-7
10 print "Oh, that's why it's False."
11 print "How about some more. "
12 print "Is it greater?", 5 > -2
13 print "Is it greater or equal?", 5 >= -2
14 print "Is it less or equal?", 5 <= -2

The author says " Notice the math seems “wrong”? There are no fractions,
only whole numbers. Find out why by researching what a “floating point”
number is."
I have to rewrite it to use floating point numbers so it's more accurate. I
have read the lines of code and only line 3 and 5 needs to be changed.

I came up with:
print "Roosters", 100 - float(25) * 3 % 4

This is for line 3 so it is more precised. Is it correct what I did? What do
I have to do for line 5?







Thanks in advance!


Regards,
amt.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating point exercise 3 from Learn python the hard way

2011-06-13 Thread Válas Péter
2011/6/13 amt <0101...@gmail.com>

> I came up with:
> print "Roosters", 100 - float(25) * 3 % 4
>
> This is for line 3 so it is more precised. Is it correct what I did?


I don't think so. All the operations in this line are for integers. % means
the remainder of the division,  so according to the precedence, the original
may be parenthesed as 100-(25*3%4), which is really 97 (75 divided by 4 is
18, and 3 remains).


> What do I have to do for line 5?
>

Hard to say without you share your Python version with us. Division behaves
differently in P2.x and P3.x

Also note that besides float() there is a more simple way to make a float
from an integer: write 1.0 instead of 1, and it becomes a float as well as
the result of the operation. Using the function is good if you work with a
variable.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating point exercise 3 from Learn python the hard way

2011-06-13 Thread Alan Gauld

"amt" <0101...@gmail.com> wrote

1 print "I will now count my chickens:"
2 print "Hens", 25 + 30 /6
3 print "Roosters", 100 - 25 * 3 % 4 #Output is 97
4 print "Now I will count the eggs:"
5 print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6 #Output needs to be 6,83 but
Python give me 7
6 print "Is it true that 3 + 2 < 5 - 7? "
7 print 3 + 2 < 5 - 7
8 print "What is 3 + 2?", 3 + 2
9 print "What is 5 - 7?", 5-7
10 print "Oh, that's why it's False."
11 print "How about some more. "
12 print "Is it greater?", 5 > -2
13 print "Is it greater or equal?", 5 >= -2
14 print "Is it less or equal?", 5 <= -2

I have to rewrite it to use floating point numbers so it's more 
accurate. I
have read the lines of code and only line 3 and 5 needs to be 
changed.


Some things to consider:

Can you explain your reasoning? Why do you think line 3 needs
to be changed? Why line 5?


I came up with:
print "Roosters", 100 - float(25) * 3 % 4

This is for line 3 so it is more precised.


In what way do you think this is more precise?

I don't understand your comment on line 5.
Why would the answer be 6.83?
Can you add parentheses to the expression
showing how you arrive at 6.83?

HTH,

--
Alan Gauld
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] Floating point exercise 3 from Learn python the hard way

2011-06-13 Thread amt
Hello, my version is Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39). The
book only talks about Python 2.x.

So, how do I solve the exercise?

3. print "Roosters", 100 - 25 * 3 % 4.00
5. print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4.00 + 6

Is this correct? I'm a bit confused at line 5 because python returns 6,75
and wolfram alpha tells me the result of that expression is 6,83.

Sorry, my math is VERY rusty.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Medical Decision-Making Question

2011-06-13 Thread عمـ نوفل ـاد
On Mon, Jun 13, 2011 at 5:22 PM, Fred G  wrote:

> Hello--
>
> I'm a pre-med student interested in decision-making as applied to medical
> decisions.  I am trying to build a medical decision-making algorithm and am
> pretty stuck on a few things.
>
> I've built a file that contains a list of many diseases and their
> associated symptoms.  For example, here are the column headers and two
> sample rows (the "|" = "or"):
> DiseaseSymptoms
> Cold
> sore_throat|runny_nose|congestion|cough|aches|slight_fever
> Flu
> sore_throat|fever|headache|muscle_aches|soreness|congestion|cough|returning_fever
>
> My questions are the following:
> a)  How's the best way to make it so I can have a user type in a list of
> symptoms and then have the computer tell the user the possible diseases that
> share those symptoms? In other words, on a high-level I have a pretty good
> idea of what I want my algorithm to do-- but I need help implementing the
> basic version first.  I'd like to do the following:
> >>>Please enter a list of symptoms
> >>>[user_input]
> >>>Possible diseases include: x, y, z
>
> b)Once I get that working, could anyone point me to good code already
> written in Python such that I could have a model (for syntax and overall
> structure) for figuring out how to make the computer evaluate more factors
> such as: patient age, patient history, and even downloading archival data
> for patients in the same demographic group?
>
> Thanks!
>
> There are lots of machine learning algorithms that do exactly what you
> want. Take a look at memory-based learning, one of the easiest to understand
> ML algorithms, and its TiMBL implementation here:
> http://ilk.uvt.nl/timbl/
>
>
and the Python binding here:

http://ilk.uvt.nl/~sander/software/python-timbl.html

>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating point exercise 3 from Learn python the hard way

2011-06-13 Thread amt
>
>
> Can you explain your reasoning? Why do you think line 3 needs
> to be changed? Why line 5?


Well the exercise says: "Rewrite ex3.py to use floating point numbers so
it’s more accurate (hint: 20.0 is floating point)."

I am honestly confused. I have read the exercise and found three lines that
could use the floating point(2,3 and line 5). This is were the confusion is
appearing. I can understand why at line 5 I use floating point. 6,75 is more
precise than saying 7. But I can't understand at line 2 and 3. I mean it
makes no difference for me. Saying 30 or 30.0 is the same thing. As well as
saying 97 or 97.0.

>
>  I came up with:
>> print "Roosters", 100 - float(25) * 3 % 4
>>
>> This is for line 3 so it is more precised.
>>
>
> In what way do you think this is more precise?
>
As I said, I am confused when it comes to line 2 and 3. But I think having
more digits after the " ." makes it more precise.

>
> I don't understand your comment on line 5.
> Why would the answer be 6.83?
> Can you add parentheses to the expression
> showing how you arrive at 6.83?
>

The answer at line 5 is 7 because I have integers and I think Python
approximates. I have done line 5 with pencil and paper: 3 + 2 + 1 - 5 = 1, 1
+ 4%2 = 1, 1 - (1/4)= 1, 1 + 6 = 7
If I use floating point the right answer will be 6,75 but I don't know how
to get to this answer. On paper I got 7 not 6,75. I'm horrible at math right
now, so please forgive me.

> HTH,
>
> --
> Alan Gauld
> 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
>


Thanks for helping me out!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OT] Re: Floating Point Craziness

2011-06-13 Thread Emile van Sebille

On 6/12/2011 1:55 PM Andre' Walker-Loud said...

Hi Alan,


* 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?


Here is a quick back of the envelope estimate for you.  (While I am still 
learning the Python, I can answer this one!)

The angle subtended by a dime on the earth is (approximately) given by

sin( theta ) = d / sqrt( R^2 + d^2 )

where

d = 1 cm (the diameter of a dime)
R = 384,403 km (the average distance from the center of the earth to the center 
of the moon - the moon traverses an elliptical path about the earth)

To make the approximation simple, take advantage of the series expansion for 
sin (theta) and 1 / sqrt(R^2 + d^2)

first

d / sqrt( R^2 + d^2 ) = d / R * 1 / sqrt(1 + d^2 / R^2 )
~= d / R * (1 - 1/2 * d^2 / R^2 + ...)

now

d / R = 1 * e-2 / (384403 * e3)
~= 3 * e-11

so the d^2 / R^2 correction will be very small, and won't effect the 
determination.  So we now have

sin (theta) ~= d / R

This will be a very small angle.  The next approximation to make is for small 
angles

sin (theta) ~= theta + ...

leaving us with

theta ~= d / R


To be approximate, assume the precision you need is equal to the size of the 
dime.  This means you need an precision of

d theta ~= d/R ~= 3 * e-11 ( = 3 * 10^{-11} if you aren't familiar with the "e" 
notation)

this is the minimum precision you would need in both the "x" and "y" direction 
to accurately hit the dime on the moon with your laser (at its average distance).

Corrections to this estimate will come from the fact that the moon's radius is 
~1737 km and the earth's radius is ~6370 km, so you are actually this much 
closer (R is this much smaller).

Of course both the earth is spinning and the moon is moving relative to us, so 
you would have to account for those extra corrections as well.


Hope that wasn't too much info,




Of course not.  I enjoyed it.  However, don't you need to work 
divergence in, as per wikipedia, "...At the Moon's surface, the beam is 
only about 6.5 kilometers (four miles) wide[6] and scientists liken the 
task of aiming the beam to using a rifle to hit a moving dime 3 
kilometers (two miles) away."


(http://en.wikipedia.org/wiki/Lunar_Laser_Ranging_experiment)

Emile

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating point exercise 3 from Learn python the hard way

2011-06-13 Thread Walter Prins
Hi,

On 13 June 2011 20:28, amt <0101...@gmail.com> wrote:

>
>> Can you explain your reasoning? Why do you think line 3 needs
>> to be changed? Why line 5?
>
>
> Well the exercise says: "Rewrite ex3.py to use floating point numbers so
> it’s more accurate (hint: 20.0 is floating point)."
>
> I am honestly confused. I have read the exercise and found three lines that
> could use the floating point(2,3 and line 5). This is were the confusion is
> appearing. I can understand why at line 5 I use floating point. 6,75 is more
> precise than saying 7. But I can't understand at line 2 and 3. I mean it
> makes no difference for me. Saying 30 or 30.0 is the same thing. As well as
> saying 97 or 97.0.
>

OK, the point is that, although to *you* 30 and 30.0 is the same thing, the
fact is that to Python they're not the same thing.  Cast yourself back to
your 1st and 2nd grade math classes, where you learned about integer (whole
numbers) and integer maths (e.g integer division), then later on fractions
and rational numbers, and later still, irrational numbers and so on.  The
point is that Python similary interprets a number literal as a certain type,
and has a set of rules to decide how to handle arithmetic based on the types
of numbers it sees.  An expression such as:

1 / 2

consists of 2 integers and a division operator.  Now as humans we can
instantly interpret this in several ways.  Python will have one way that it
uses, unless you explicitly force it modify its interpretation.  Introducing
a float() call converts the paramter so that the output is a float, thus
affecting the rest of the expression.  Similarly, putting a "dot zero" after
a number forces Python to interpret it as a floating point number, thus
again affecting the rest of the expression evaluation.

Hope that helps.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Kĩnũthia Mũchane

On 06/12/2011 08:13 PM, Steven D'Aprano wrote:

Ryan Strunk wrote:

Hi everyone,
I'm designing a timeline. When the user presses the right arrow, 0.1 is
added to the current position. The user can add events to the 
timeline, and

can later scroll back across those events to see what they are. But
something I absolutely don't understand is happening:
I used the program to place events at 1.1, 2.1, and 3.1. Here is the 
end of

the debug output for arrowing to 3.1 and placing the event:
position = 2.7
position = 2.8
position = 2.9
position = 3.0
position = 3.1
event placed.
Everything appears straight forward. 



It only *appears* straight forward, it actually isn't. That's because 
the printed output is rounded so as to look nice. Compare:


>>> x = 1/10.0
>>> print(x)  # displayed as nicely as possible
0.1
>>> print('%.25f' % x)  # display 25 decimal places
0.155511151


For speed and simplicity, floats are stored by the computer using 
fractional powers of two. That's fine for numbers which are powers of 
two (1/2, 1/4, 1/256, and sums of such) but numbers that humans like 
to use tend to be powers of 10, not 2.


Unfortunately, many common fractions cannot be written exactly in 
binary. You're probably familiar with the fact that fractions like 1/3 
cannot be written exactly in decimal:


1/3 = 0.... goes on forever

Does it? :-)


The same is true for some numbers in binary:

1/10 in decimal = 1/16 + 1/32 + 1/256 + ...

also goes on forever. Written in fractional bits:

1/10 decimal = 0.00011001100110011... in binary

Since floats can only store a finite number of bits, 1/10 cannot be 
stored exactly. It turns out that the number stored is a tiny bit 
larger than 1/10:


>>> Fraction.from_float(0.1) - Fraction(1)/10
Fraction(1, 180143985094819840)

Rounding doesn't help: 0.1 is already rounded as close to 1/10 as it 
can possibly get.


Now, when you print the dictionary containing those floats, Python 
displays (almost) the full precision:


>>> print {1: 0.1}
{1: 0.10001}


In newer versions of Python, it may do a nicer job of printing the 
float so that the true value is hidden. E.g. in Python 3.1 I see:



>>> print({1: 0.1})
{1: 0.1}

but don't be fooled: Python's print display is pulling the wool over 
your eyes, the actual value is closer to 0.10001.



One consequence of that is that adding 0.1 ten times does not give 1 
exactly, but slightly less than 1:


>>> x = 0.1
>>> 1 - sum([x]*10)
1.1102230246251565e-16


(P.S. this is why you should never use floats for currency. All those 
missing and excess fractions of a cent add up to real money.)



To avoid this, you can:


* Upgrade to a newer version of Python that lies to you more often, so 
that you can go on living in blissful ignorance (until such time as 
you run into a more serious problem with floats);


* Use the fraction module, or the decimal module, but they are slower 
than floats; or


* Instead of counting your timeline in increments of 0.1, scale 
everything by 10 so the increment is 1.


That is, instead of:

2.0  2.1  2.2  2.3 ...

you will have

20  21  22  23  24  ...


* Or you just get used to the fact that some numbers are not exact in 
floating point.








--
Kĩnũthia

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating point exercise 3 from Learn python the hard way

2011-06-13 Thread Alan Gauld


"amt" <0101...@gmail.com> wrote in message


I am honestly confused. I have read the exercise and found
three lines that could use the floating point(2,3 and line 5).



I can understand why at line 5 I use floating point. 6,75 is more
precise than saying 7.


Exactly, no problem with line 5 (except the odd comment about 6.83)

But I can't understand at line 2 and 3. I mean it makes no 
difference

for me. Saying 30 or 30.0 is the same thing.
As well as saying 97 or 97.0.


Precisely, thats why I asked the question.


print "Roosters", 100 - float(25) * 3 % 4

This is for line 3 so it is more precised.



In what way do you think this is more precise?

As I said, I am confused when it comes to line 2 and 3.
But I think having more digits after the " ." makes it more
precise.


It depends on the definition of precision.
As per a recent thread floating point numbers are
less precise in an absolute sense for integer values
because they are stored as approximations, but the
representation with multiple decimal places is a
greater precision mathematically speaking.


I don't understand your comment on line 5.
Why would the answer be 6.83?



The answer at line 5 is 7 because I have integers
and I think Python approximates.


It doesn't approximate but it does use integer
arithmetic exactly.


I have done line 5 with pencil and paper:
3 + 2 + 1 - 5 = 1, 1+ 4%2 = 1, 1 - (1/4)= 1, 1 + 6 = 7


Right, that's the integer version.


If I use floating point the right answer will be 6,75

but I don't know how to get to this answer.


3 + 2 + 1 - 5 = 1,
1+ 4%2 = 1,
1 - (1/4)= 1,  -> 1 - 0.25 = 0.75


0.75 + 6 = 6.75

HTH,


--
Alan Gauld
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] Lists

2011-06-13 Thread Kĩnũthia Mũchane

On 06/13/2011 12:17 AM, R. Berman wrote:

Having followed this absurd thread from its beginning hopefully to this, the 
end of it. Everyone replying to your diatribe has been incredibly polite to 
you. One of the moderators tried to explain the obvious to you. This is a 
Python group. Python is to most of us a delightful language. To others it is a 
snake. It is not a god a priest or a rabbi. You are arguing religion and issues 
pertaining to very elementary sophistry. You are acting the fool. Enough. You 
have crossed the line and have become the 'Troll mediocre'.  Go forth and spew 
your venom  elsewhere.

Hehehehe!! :-) I could not reply because I do not know any big words.

Robert


-Original Message-
From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
bounces+bermanrl=cfl.rr@python.org] On Behalf Of Piotr Kaminski
Sent: Sunday, June 12, 2011 4:06 PM
To: tutor@python.org
Subject: Re: [Tutor] Lists

Dnia 11-06-2011 o 17:51:03 Piotr Kamiński
napisał(a):


Dnia 11-06-2011 o 17:30:50 Alan Gauld
napisał(a):


"Piotr Kamiński"  wrote


  This is a *technical* list, as I understand it, solely

dedicated to
...


Since this seems to be something we can all agree on
can we consider this discussion closed and get back
to Python?

If you wish to continue the philosophical debate please
take it off list.

Alan g.
List moderator.


OK.

I like this style of talking - no feelings hurt, *including

Christian

ones as well*.
Thank you.

Piotr.


To be perfectly clear, as I've got the impression that my words were
interpreted in various ways by different people: the "thank you" in
my
reply to Alan Gauld's message, *is not* a sign of
subservience/weakness,
my seeking his approval or a similar attitude.

I thanked him strictly for *the *polite* style of talking* on the
list; I
do not expect Alan Gauld or any other Tutor list user to agree with
or
approve of any of my philosophical views.

In other words, *in my culture* thanking someone for something (and,
by
the way: apologising to someone for a mistake made) is strictly a
sign of
*politeness*, not of some weakness, defeat, being a losing party, a
member
of a lower social class etc.

Over and out.

Piotr
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


--
I am using the free version of SPAMfighter.
We are a community of 7 million users fighting spam.
SPAMfighter has removed 237 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

The Professional version does not have this message


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



--
Kĩnũthia

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Medical Decision-Making Question

2011-06-13 Thread Fred G
Thanks guys for all the feedback.

re Jim's comments: I completely agree that the difference b/t "slight" fever
and "returning" fever, etc will pose some problems.  My hunch is that
initially I'll just do something like make "fever" be the only one for now
w/ the obvious caveat that a few more diseases would not be eliminated than
actually should be.  Building on this, another challenging problem will be
how to code the fact that when a symptom occurs early it usually means
something else than if it returns later in the course of an illness.  I'm
not 100% sure how I'll handle this, but I think the first priority is
getting access to a dataset and getting the bot up and running before I
focus on this.

re Steve's comments: hmm, sounds like I really should take an AI class.
 This problem is just really exciting and driving me, and I'm glad you
pointed out that this will probably take a lot more time than I had
predicted.  I'm pretty motivated personally to solve it.  I had a few more
questions about your code:
a) Why did you choose not to use a dictionary to store the diseases (keys)
and their possible values (symptoms)?  That seemed the most intuitive to me,
like, what I want to do is have it such that we enter in a few symptoms and
then all the keys without those symptoms are automatically eliminated.  I've
been off and on teaching myself python for the last 6 months and have
experience in Java.  I mean, I think I want a structure like this:
1) Main class
-this class calls the diagnose_disease class based on the set of entered
symptoms and demographic information (ie age, location, season (winter,
spring, fall, etc), patient history)
2) Diagnose_disease class
-this is the heart of the project.  Based on the entered symptoms, it keeps
narrowing down the list of possible diseases.  Ideally it would ask
follow-up questions of the user to even further narrow down the list of
possible diseases, but that's going to have to wait until I get the rest
working.
3) Dictionary Class
-this class contains a *dictionary??* of all possible diseases and their
associated symptoms.  Assuming in a standardized form for now (such that
"slight_fever" and "returning_fever" are simply coded as "fever" for now,
etc).

does this seem like the best way to go about it?

re: James.  I completely agree that my first step should be getting access
to a dataset.  I need to know the format, etc of it before I really can
progress on this.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Excited about python

2011-06-13 Thread Siim Märtmaa
2011/6/10 Kaustubh Pratap chand :
> Can you recommend a book for a person like me which comes with a C
> background and the book covers all essential algoithmic methods and
> examples?

You, might find "Data Structures and Algorithms with Object-Oriented
Design Patterns in Python"
by Bruno R. Preiss useful.

http://www.brpreiss.com/books/opus7/

It is not about python or how it differs from c, but about algorithms,
with examples in python.
The book is meant for cs students.

There are a lot of source examples and other versions in C++, Java,
C#, Ruby, Lua, Perl, PHP. So you can compare an avl-tree
implementation in python, php and c++.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Steven D'Aprano

Kĩnũthia Mũchane wrote:

On 06/12/2011 08:13 PM, Steven D'Aprano wrote:


Unfortunately, many common fractions cannot be written exactly in 
binary. You're probably familiar with the fact that fractions like 1/3 
cannot be written exactly in decimal:


1/3 = 0.... goes on forever

Does it? :-)


Yes.

0.3 is not 1/3, it is 3/10, not 3/9.
0.33 is not 1/3, it is 33/100, not 33/99.
0.333 is not 1/3, it is 333/1000, not 333/999.
...
0.33 is not 1/3, it is 33/100 instead of 
33/99.



And so forth. No matter how many 3s you have, it will always be just 
short of 1/3. Anything less than an infinite number of decimal places is 
not 1/3 exactly, but some approximation less than 1/3.




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Medical Decision-Making Question

2011-06-13 Thread Alan Gauld


"Fred G"  wrote

re Steve's comments: hmm, sounds like I really should take an AI 
class.
This problem is just really exciting and driving me, and I'm glad 
you

pointed out that this will probably take a lot more time than I had
predicted.


I assume you know that there are several commerial packages
designed for the use of medical staff in surgeries etc? Not being
a doctor I can't comment on their quality or accuracy but they
cost big bucks...

--
Alan Gauld
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] Medical Decision-Making Question

2011-06-13 Thread Jim Richardson
On Mon, Jun 13, 2011 at 3:35 PM, Fred G  wrote:
> Thanks guys for all the feedback.
> re Jim's comments: I completely agree that the difference b/t "slight" fever
> and "returning" fever, etc will pose some problems.  My hunch is that
> initially I'll just do something like make "fever" be the only one for now
> w/ the obvious caveat that a few more diseases would not be eliminated than
> actually should be.  Building on this, another challenging problem will be
> how to code the fact that when a symptom occurs early it usually means
> something else than if it returns later in the course of an illness.  I'm
> not 100% sure how I'll handle this, but I think the first priority is
> getting access to a dataset and getting the bot up and running before I
> focus on this.
> re Steve's comments: hmm, sounds like I really should take an AI class.
>  This problem is just really exciting and driving me, and I'm glad you
> pointed out that this will probably take a lot more time than I had
> predicted.  I'm pretty motivated personally to solve it.  I had a few more
> questions about your code:
> a) Why did you choose not to use a dictionary to store the diseases (keys)
> and their possible values (symptoms)?  That seemed the most intuitive to me,
> like, what I want to do is have it such that we enter in a few symptoms and
> then all the keys without those symptoms are automatically eliminated.  I've
> been off and on teaching myself python for the last 6 months and have
> experience in Java.  I mean, I think I want a structure like this:


If you are going to use dicts, I'd suggest you flip it around, have
the symptom be the key, and the list of diseases related to a given
symptom, be the value.

But that sounds more like a map:reduce problem or an sql query problem
than a dict one.   I haven't used it in over 20 years, and I was no
expert then, but this sounds like a prolog problem :) To maintain the
pythonical nature of the list, https://bitbucket.org/cfbolz/pyrolog/
is something I found. Looks interesting.




> 1) Main class
> -this class calls the diagnose_disease class based on the set of entered
> symptoms and demographic information (ie age, location, season (winter,
> spring, fall, etc), patient history)
> 2) Diagnose_disease class
> -this is the heart of the project.  Based on the entered symptoms, it keeps
> narrowing down the list of possible diseases.  Ideally it would ask
> follow-up questions of the user to even further narrow down the list of
> possible diseases, but that's going to have to wait until I get the rest
> working.
> 3) Dictionary Class
> -this class contains a *dictionary??* of all possible diseases and their
> associated symptoms.  Assuming in a standardized form for now (such that
> "slight_fever" and "returning_fever" are simply coded as "fever" for now,
> etc).
> does this seem like the best way to go about it?
> re: James.  I completely agree that my first step should be getting access
> to a dataset.  I need to know the format, etc of it before I really can
> progress on this.
>
>



-- 
http://neon-buddha.net
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OT] Re: Floating Point Craziness

2011-06-13 Thread Andre' Walker-Loud
On Jun 13, 2011, at 1:44 PM, Emile van Sebille  wrote:

> On 6/12/2011 1:55 PM Andre' Walker-Loud said...
>> Hi Alan,
>> 
 * 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?
>> 
>> Here is a quick back of the envelope estimate for you.  (While I am still 
>> learning the Python, I can answer this one!)
>> 
>> The angle subtended by a dime on the earth is (approximately) given by
>> 
>> sin( theta ) = d / sqrt( R^2 + d^2 )
>> 
>> where
>> 
>> d = 1 cm (the diameter of a dime)
>> R = 384,403 km (the average distance from the center of the earth to the 
>> center of the moon - the moon traverses an elliptical path about the earth)
>> 
>> To make the approximation simple, take advantage of the series expansion for 
>> sin (theta) and 1 / sqrt(R^2 + d^2)
>> 
>> first
>> 
>> d / sqrt( R^2 + d^2 ) = d / R * 1 / sqrt(1 + d^2 / R^2 )
>>~= d / R * (1 - 1/2 * d^2 / R^2 + ...)
>> 
>> now
>> 
>> d / R = 1 * e-2 / (384403 * e3)
>>~= 3 * e-11
>> 
>> so the d^2 / R^2 correction will be very small, and won't effect the 
>> determination.  So we now have
>> 
>> sin (theta) ~= d / R
>> 
>> This will be a very small angle.  The next approximation to make is for 
>> small angles
>> 
>> sin (theta) ~= theta + ...
>> 
>> leaving us with
>> 
>> theta ~= d / R
>> 
>> 
>> To be approximate, assume the precision you need is equal to the size of the 
>> dime.  This means you need an precision of
>> 
>> d theta ~= d/R ~= 3 * e-11 ( = 3 * 10^{-11} if you aren't familiar with the 
>> "e" notation)
>> 
>> this is the minimum precision you would need in both the "x" and "y" 
>> direction to accurately hit the dime on the moon with your laser (at its 
>> average distance).
>> 
>> Corrections to this estimate will come from the fact that the moon's radius 
>> is ~1737 km and the earth's radius is ~6370 km, so you are actually this 
>> much closer (R is this much smaller).
>> 
>> Of course both the earth is spinning and the moon is moving relative to us, 
>> so you would have to account for those extra corrections as well.
>> 
>> 
>> Hope that wasn't too much info,
>> 
> 
> 
> Of course not.  I enjoyed it.  However, don't you need to work divergence in, 
> as per wikipedia, "...At the Moon's surface, the beam is only about 6.5 
> kilometers (four miles) wide[6] and scientists liken the task of aiming the 
> beam to using a rifle to hit a moving dime 3 kilometers (two miles) away."
> 
> (http://en.wikipedia.org/wiki/Lunar_Laser_Ranging_experiment)


Of course, I was performing just the 'theoretical' calculation.  It is up to 
others to dtermine if it is actually practical :)

Andre



> 
> Emile
> 
> ___
> 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] Medical Decision-Making Question

2011-06-13 Thread R. Alan Monroe

> a)  How's the best way to make it so I can have a user type in a list of
> symptoms and then have the computer tell the user the possible diseases that
> share those symptoms?

Good question. The first decent idea that came to mind was searching
through a cartesian join of all diseases & symptoms:
{ (disease1, symptom1),
  (disease1, symptom2),
  (disease2, symptom1),
  (disease2, symptom2) }

Searching for (flu, runny_nose) would not find anything (given the
sample data in your original message) so you could rule out flu.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor