This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests and have Scott Selikoff and Jeanne Boyarsky on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

python codes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone help me please to understand this lines if ever someone has knowledge to these. I dont know what is the meaning of "Places" and the number 2 inside the parentheses.

#Read Temperature sensor
def ReadTemperature(places):
    humidity, temperature = Adafruit_DHT.read_retry(sensor,pin)
    temperature = round(humidity,places)
    return temperature


while True:
#take Temperature Reading via DHT22
    temperature_percentage = ReadTemperature(2)
 
Ranch Foreman
Posts: 2382
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is a variable that you have created and passing to the function.
 
Saloon Keeper
Posts: 23252
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that you're using Circuit Python. I moved this question to the Arduino forum, although it's possible that you're using a Raspberry Pi. I just happen to use the DHT units on Arduinos - although in Arduino's C++ like language, not Python.

The round() function takes a numeric value (humidity) and rounds it to a specified number of decimal places. And actually, that code is defective, because it's treating temperature and humidity as the same thing. In this case, since you passed the value 2 to ReadTemperature, it rounds the humidity (!!!) to 2 decimals, then returns it as a "temperature".

The proper code should be like this:


I don't know what generally-accepted name formation rules are for Python, but I always use either C-like (read_temperature) or Java-like (readTemperature). Beginning a name with a capital letter is usually something only done for classnames and constant names (which are generally all upper-case).

And the code tags goe around the formatted text. That's why my code is in a box, but yours has an empty box and no pretty code. Check Use Code Tags for details.
 
Marshal
Posts: 3398
493
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Manubay wrote:I dont know what is the meaning of "Places" ...


Places specifies the number of devcimal places to use with the Python round function

Michael Manubay wrote:... and the number 2 inside the parentheses.


It most likely means than there are multiple DHT sensors, and the number 2 specifies to read from the the senor on GPIO pin #2.


Edit: looks like I didn't read the question properly and I didn't notice Tim's response. Ugh  
 
My pie came with a little toothpic holding up this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic