Re: [Tutor] Count for loops

2017-04-12 Thread D . V . N . Sarma డి . వి . ఎన్ . శర్మ
A lot of confusion is caused by the print function converting an integer or
float
to a string before printing to console. thus both '1234 and '1234' are
shown as
1234 on the console. Similarly '15.4' and 15.4 are displayed as 15.4. There
is no way
to tell which is a string, which is an int and which is a float by looking
at the display on
console. In order to find which is which one has to type the variables.


>>> s = '1234'

>>> print(s)
1234

>>> s = 1234

>>> print(s)
1234

>>> s = '15.4'

>>> print(s)
15.4

>>> s = 15.4

>>> print(s)
15.4

regards,
Sarma.

On Wed, Apr 12, 2017 at 11:11 AM, eryk sun  wrote:

> On Wed, Apr 12, 2017 at 4:03 AM, boB Stepp  wrote:
> >
> > I have not used the decimal module (until tonight).  I just now played
> > around with it some, but cannot get it to do an exact conversion of
> > the number under discussion to a string using str().
>
> Pass a string to the constructor:
>
> >>> d = decimal.Decimal('3.141592653589793238462643383279
> 50288419716939')
> >>> str(d)
> '3.14159265358979323846264338327950288419716939'
>
> When formatting for printing, note that classic string interpolation
> has to first convert the Decimal to a float, which only has 15 digits
> of precision (15.95 rounded down).
>
> >>> '%.44f' % d
> '3.14159265358979311599796346854418516159057617'
> >>> '%.44f' % float(d)
> '3.14159265358979311599796346854418516159057617'
>
> The result is more accurate using Python's newer string formatting
> system, which allows types to define a custom __format__ method.
>
> >>> '{:.44f}'.format(d)
> '3.14159265358979323846264338327950288419716939'
> >>> format(d, '.44f')
> '3.14159265358979323846264338327950288419716939'
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question to Phyton and XBee

2017-04-12 Thread Alan Gauld via Tutor
On 12/04/17 15:32, Daniel Berger wrote:

>For me it is not clear what is going wrong and I would be happy to get
>some help to solve the problem.

This list is for the core language and library, so while we
can help with installing third party packages that doesn't
mean anyone here will know how to use them. You might get
lucky and find somebody, but you are more likely to find
someone on a dedicated XBee support forum.

If both of those options fail then you can try the main
Python list.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Startup Python

2017-04-12 Thread Alan Gauld via Tutor
On 12/04/17 13:47, Wim Berrelkamp wrote:

 a=2

Here you assign the number 2 to 'a'

 d=a+4
 print(d)
> 6
> a=input('-->' )

Here you assign whatever character(s) the user types to 'a'.
The fact that it looks like 2 doesn't change the fact that it
is really the character '2'. So you need to convert it to
a number using either int() or float()

a = int(input('-->'))
or
a = float(input('-->'))

> print(a)
> d=a+4
> print(d)
> 

> I tried to use float(), but nothing works.
> What am I doing wrong ?

I don't know, because you don't show us how you tried to
use float(), but if you apply it as shown above it
should work.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Startup Python

2017-04-12 Thread Wim Berrelkamp
Dear Tutor,

In earlier days I programmed a lot with Quick Basic in DOS.
Now I retiered, I hoped to have Python as a platform.
So I installed it and saw a lot of simmularity with Basic.

I hope you can help me with the following, which should not be difficult,
but I cannot find the solution.

When I type this:

>>> a=2
>>> d=a+4
>>> print(d)
6

I got the correct answer.

When I try this to run it in a Module:

a=input('-->' )
print(a)
d=a+4
print(d)

I get this as a result:


input test.py
-->2
2
Traceback (most recent call last):
  File
"C:\Users\Gebruiker\AppData\Local\Programs\Python\Python36\Lib\idlelib\input
test.py", line 3, in 
d=a+4
TypeError: must be str, not int
>>>

I receive this message.

I tried to use float(), but nothing works.
What am I doing wrong ?

Thanks in advance !
Regards,
Wim Berrelkamp
Groningen, The Netherlands
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question to Phyton and XBee

2017-04-12 Thread Daniel Berger
   Hello,

   thank you very much for your help. I have done a mistake during
   installation.
   I have tested the code for reading data from Xbee:

 #! /usr/bin/python
 # Import and init an XBee device
 from xbee import XBee, ZigBee
 import serial
 ser = serial.Serial('COM4', 9600)
 xbee = XBee(ser)
 while True:
 try:
 response =  xbee.wait_read_frame()
 print response
 except KeyboardInterrupt:
 break
 ser.close()

   At the moment it is not possible to get any data received by the Xbee,
   although it is possible to read the data by XCTU. I have chosen the
   following setup:
   - A TMP36-sensor is connected to an Arduino Uno
   - A Sparkfun XBee-shield with an XBee S2C is mounted on the Arduino
   (Router). The Arduino is connected to COM3.
   - COM4 is connected with a Sparkfun XBee-Explorer (USB-connection).
   Another XBee S2C is connected on the explorer. This XBee is the
   coordinator.
   If I send sensor data (sensor reading and sending to Xbee is done by
   Arduino Software) from the router to the coordinator, I'm able to read the
   data frames by XCTU and the results make sense. If I use the Python-code
   above, I did not get any data frames, although the RSSI-diodes of router
   and coordinator are blinking independently from the software (XCTU or
   Python) I use.
   For me it is not clear what is going wrong and I would be happy to get
   some help to solve the problem.

   Regards and thank you very much
   Daniel Berger




   Gesendet: Dienstag, 11. April 2017 um 21:04 Uhr
   Von: "Marc Tompkins" 
   An: "Daniel Berger" 
   Cc: "tutor@python.org" 
   Betreff: Re: [Tutor] Question to Phyton and XBee
   On Tue, Apr 11, 2017 at 9:12 AM, Daniel Berger <[1]berg...@gmx.de> wrote:

Hello,

I have installed the modules to control xbee with Python
[2]https://pypi.python.org/pypi/XBee). Afterwards I have set the path
variable on C:\Python27\python-xbee-master and also the
 subdirectories. To
check, if the modules are available, I have written the code as
recommended ([3]https://pypi.python.org/pypi/XBee)

# Import and init xbee device
from xbee import XBee
import serial
import arduino

The interpreter gave the error message
File "C:/Users/daniel/PycharmProjects/hardware_test/test_xbee.py",
 line 2,
in 
from xbee import XBee
ImportError: No module named xbee

I have done the same with
 [4]https://github.com/nioinnovation/python-xbee and
it have the same effect.
As I'm not very familiar with Python, I would like to know, what is
 going
wrong and how I can find the module.


   How did you install it?  If you use the very simplest method -  "pip
   install xbee" - it should automatically take care of the path for you.



References

   Visible links
   1. mailto:berg...@gmx.de
   2. https://pypi.python.org/pypi/XBee
   3. https://pypi.python.org/pypi/XBee
   4. https://github.com/nioinnovation/python-xbee
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor