0% found this document useful (0 votes)
12 views

Python 1st Chapter

It is good

Uploaded by

bhargavyellanki
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
12 views

Python 1st Chapter

It is good

Uploaded by

bhargavyellanki
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 23
| (oH wrropuction Internet of Things (loT) is the networking of physical objects that contain electronics embedded within their architecture in order to communicate and sense interaction, +t each other (ot) with respect to the external environment. In the upcoming amongst years, loT-based technology will offer advanced levels of services and practically change the way people lead their daily lives. Advancements in medicine, power, gene therapies, agriculture, smart cities and smart homes are just a very few of the categorical examples where loT is strongly established. HE oT The Internet of Things (IoT) is a system of interrelated computing devices, mechanical and digital machines, objects, animals, or people that are provided with unique identifiers and the ability to transfer data over a network without requiring human-to-human |or) human-to-computer interaction. 2 APPLICATION OF 10T Applications of Internet of Things (IoT) : ‘© Smart Door access control system. © Smart lighting for home and office. ... ‘* Automated Gate and garage. ... '* Smart thermostats and humidity controllers. ... © Traffic Management. ... + Smart lighting on streets. Pollution monitoring and reporting. . fomart Parking Solutions. COMPARISON TABLE FOR ADVANTAGES AND DISADVANTAGES OF Minimizes the human work and effort. Increased privacy concerns. _| Saves time and effor. Increased unemployment rates. . | Good for personal safety and security. Highly dependent on the internet. Useful in traffic and other tracking (or) Lack of mental and physical activity by humans leading to health issues, Python Introduction and Raspberry PI {_ 5. | Beneficial forthe healthcare industry. | I | 6. | Improved security in homes and offices. |, 7. | Reduced use of many electronic devices as | Absence of international standards for better | ‘one dévice does the job of a lot of other | communication, | devices. | Lack of security. IDENTIFY COMPONENTS OF RASPBERRY PI-3 FIG 1.1 : Diagram of the Raspberry Pi The Raspberry Pi device looks like a motherboard, with the mounted chips and ports exposed (something you'd expect to see only if you opened up your computer and looked at its internal boards), but it has all the components you need to connect input, ‘output, and storage devices and start computing. You'll encounter two models of the device : Model A and Model B. The only real differences are the addition of Ethernet and an extra USB port on the more expensive Model B. Here are the various components on the Raspberry Pi boar: — — This is a Broadcom BCM2835 System on a Chip (SoC) that’s made up of an ARM central processing unit (CPU) and a videocore 4 sraphies processing unit (GPU). The CPU handles all the computations) ‘hat make a computer work (aking input, doing ealeulations and {nd the GPU handles graphics output These are exposed general-purpose input/output connection points that will allow the real hardware hobbyists the opportunity to tinker. ARM CPU/GPU opment — + | RCA ‘An RCA jack allows connect output devices. + | Audio out “This is «standard 3.55-millimeter jack for connection of audio oupy: devices such as headphones or speakers. There is no audio in, . + | ueps Light-emitting diodes, for all of your indicator light needs. aL = This is a common connection port for peripheral devices of all (including your mouse and keyboard). Model A has one and Mccall } has two. You can use a USB hub to expand the number of ports (ory plug your mouse into your keyboard if it has its own USB port, . HDMI This connector allows you to hook up a high-definition television (or) other compatible device using an HDMI cable. “ = Power | This is a Sv Micro USB power connector into which you can plug compatible power supply. + | SDcardslot This is a full-sized SD card slot. An SD card ‘with an operating aaa (OS) installed is required for booting the device. They are available purchase from the manufacturers, but you can also download an OS save it to the card yourself if you have a Linux machine and the where Bi withal. + | Ethernet ‘This connector allows for wired network access and is only available on the model B. PI Robots are able to sense and interact with the environment through a wide range e GENERAL PURPOSE INPUT AND OUTPUT PINS (GPIO) ON RASPBE! components. So that a robot can make decisions and perform actions, it uses a processor to information from and send signals back to the other components. A standard interface for connecting a single-board computer (or) microprocessor ‘other components is through General-Purpose Input/Output (GPIO) pins. _ Controlling robots using the Raspberry Pi : Raspberry Pi computers are wond in what they can do. Among the many applications they can be used for, ‘one of the most exciting and powerful. between the Raspberry Pi and the outside world. Using the pins, you can program the Raspberry Pi to switch components on and off (output), (or) receive data from sensors land switches (input) nee fy a) FIG 1.2 : Raspberry Pi Models Most models of the Raspberry Pi have a 40-pin header, as shown in the image above. OF the 40 pins, 26 are GPIO pins and the others are power (or) ground pins (plus two ID EEPROM pins, which you should not play with unless you know your stuff!). Any of the GPIO pins can be designated (in software) as an input (or) output pin and used for ‘@ wide range of purposes ; whether it is turning on an LED, driving a motor, (or) Sending data to another device, the possibilities are almost endless. Early models of the Raspberry Pi A and B have a shorter header with 26 pins, as shown below. FIGL3: "The Raspberry Pi Zero models have unpopulated pins (apart from the Raspberry Pi 10 WH) so there are holes where the GPIO header is located instead of physical ins. This means you need to add a header that includes the pins yourself FIG 14: ot buggy with most models of Raspberry P B+ (or) 4. These models allow you to progra: computer (or) even a smartphone | Although it is possible to create a rob recommend using a Raspberry Pi 3B, 3) the Raspberry Pi easily and connect it to another using the inbuilt WiFi (or) Bluetooth, rather than needing to plug the Pi physically in: a screen or a keyboard and mouse. When programming the GPIO pins, there are two differe: © numbering and physical numbering. Throughout th ‘es) we will refer to the pins using the GPIO numberir. GPIO pin numbering = ways to refer to them: GPI course (and in all our resource scheme. These are the GPIO pins as the computer sees them. COE@HHEDLESGOOOE OOOH C@QOQEDD@O@OOQEOOOGLLO aspbeny PIA GPIO pine O ono @ cons Q33v Ov FIG 1.5: EEPROM O aavanced use onty The numbering of the GPIO pins is not in numerical order, instead relating t0 © numbering on the CPU of the Raspberry Pi, so there Is no easy way to rement™ them. However, you can use a reference board that fits over the pins, a printed referet (like the image above). Voltages : The voltage of a pin is labelled on the reference guide. There are two pins and two 3V3 pins, as well as a number of ground pins (OV), which Lnconfigurable. The remaining pins are all general-purpose 3V3 pins, meaning the outputs are set to 3.3 volts and the inputs are tolerant of 3.3 volts. (GRRRFERT 0» rt tion and Raspberry PI ma A GPIO pin designated as an output pin can be set to high (3.3V) (or) low (OV), ‘Components are usually attached so that setting the output to high will allow current to flow to them, while setting the output to low won't AGPIO pin that is designated as an input will allow a signal to be received by the Raspberry ’ Pi, The threshold between a high and a low signal is around 1.8V, A voltage between 1.8V and 3.3V will be read by the Raspberry Pi as high; anything lower than 1.8V will be ead as low. Do not allow an input voltage above 3.3V, (or) else you will fry your Pil WHY _BUILD A PC USING RASPBERRY PI-3 at + FIG 1.6 : Step 1: Parts Here is a list of parts you will need : Raspberry pi It is important that you get the model that I have shown. It has 4 usb ports that are crucial to this build. You will not be “able to build this with any other model. Shown is model 2. “Tinch led screen “7 inch tablet case hdmi cable usb to micro usb cable * First go to Raspberrypi.org * Click the button that says “downloads”, * Click on “Raspbian”, Download zip file for “wheezy”. * When it is done downloading, put it on your sd card by plugging it into the computer and dragging the file to the sd card, © When it is done, take the sd card and plug it into the Raspberry pi. * Set that aside. To connect the eereen to the driver board, pull the black plece on the comers out, from the main board slightly. Then insert the ribbon cable and close it. Be very cay. Also, there is some tape that you will have to remove before you are able to do t}, the small board with the buttons should be simple. Connect it to the 1, Connecting the other components. board with the cable that is supplied with mi cable to the raspberry pi, then the other en he wifi adapter and mouse into the usb por: pi. For the key board you To start off, plug in one end of the hdi the driver board for the screen Plug tl the raspberry pi. Plug the micro usb into the raspberry need some adapters. pi and screen. For the raspberry pi, plug the You will need to power your raspberry tlet. For the screen, it is a bit different. You end of the usb-micro usb into a wall out need a 2-amp, 12-volt power source. It is done! This computer is not a gaming computer. This is a coding compute: comes with Python, Scratch, and much more! It does come with a early versio Minecraft too. (UII IWSTALL OPERATING SYSTEM INTO RASPBERRY PI Software Requirements : To make our Raspberry Pi work, we need to instal Operating System (OS) into a microSD card. The Raspberry Pi Foundation made step very easy for beginners by providing a software called the Raspberry Pi Imas 1. Raspberry PI Imager : a ; Raspberry Pi FIG 1.7: XEROX PCa sal 4 Python Introduction and Raspberry PI Raspberry Pi Imager software can download an OS image and it can also write an into a microSD card. You can download it. berry PI Operating System : FIG 1.8: "The official OS for the Raspberry Pi is called the Raspberry Pi OS (formerly known as _Héspbian). You can download it separately. If you are using the Raspberry Pi Imager Software, it can download the OS for you _ The download page gives several versions of the Raspberry Pi OS (32-bit) : * With desktop and recommended software * With desktop, * Lite ie first two download options are self-exy lude the desktop GUI, planatory. The third version means it doesn't talling The Raspberry Pl Operating System : The OS needs to be installed into a lcroSD card using a computer, a mi step is to install the Raspberry Pi Imager. Run the di all the software. and the imager software. The lownloaded executable file and (ick Insta to start the ntti, After installing the software, the next step is to insert the microSD card to a card r, connected to a computer. After doing this, run the Raspberry Pi Imager software @ home screen will greet you with three buttons. Click the first button on the left la> Choose OS. Here, you will have several choices for the OS available for the Raspb: Pi board. If you don’t have a local copy of a compatible OS image, click the first ch This will download the recommended version of the Raspberry Pi OS. FIG 1.10 : Raspberry Pi Imager First Option ~ Download OS You can also choose the last option Use Custom if you already have a local imas° of a compatible OS. FIG 1.11 : Raspberry Pi Imager Last Option — Use Custom After choosing the OS image file, the next step is to select the middle button. This will give you the option to select which of the detected storage devices to use in writing the OS image. Take note that all data in the chosen device will be lost during the image writing process. Select the microSD card you will use. |B mpernimgenz = | | ‘Generic STORAGE DEVICE USB Devce-15:9 68 FIG 1.12 : Raspberry Pi Imager ~ Select Storage Device The last step in writing the image file to the microSD card is to select the third button Write. This will write the OS image file to the microSD card. Tiere rina 3 Z| ce FIG 1.13 : Raspberry Pi Imager ~ Writing to microSD card Wait for the writing and verification process to finish then click Continue. Bape imaged 2020-02-13-raspbian-busterimg has been written to Generle ‘STORAGE DEVICE USB Device ‘You can now remove the SD card from the reader FIG 1.14 : Raspberry Pi Imager ~ Writing and Verification Done First Boot : Insert the microSD card into the Raspberry Pi, connect an HDMI USB keyboard and USB mouse. Afterthe Raspberry Pi OS boots, you will be your log-in credentials, The default username is pi and default password is After logging in, you will be greeted by a desktop with a welcome window. and follow the on-screen messages to finish the setup 7 Xehox FPhorocorvins oF This Boox FIG 1.15 5 You now have a working Raspberry Pi Linux Computer. FAMILIARIZE TO PYTHON PROGRAMMING LANGUAGE Python is high level programming language which has scripting capabilities as well, (or) python is scripting language which is used to develop required software applications, client-side validation, and automation. what is scripting language ? scripting language is a computer language with a series of commands within a file that is capable of being executed without being compiled. Client-side Validation : Validation done in the browser is called client-side validation. (i) Low level language follows the below steps for the execution. * Source code. * Compilation. * Binary code (1/0). * Execution-output, ® Eg : Cobal, C etc., \ii) High level language follows the below steps for execution. * Source code. * Compilation, * Byte code (8 bits) 10110011. * Execution-o/p Eg : python, .net,java, ML, DL, Al WS) DIFFERENT VERSIONS OF PYTHONS Different Versions of Python : Python programming language is being updated regulari, with new features and support. There are a lot of updation in python versions, starte, from 1994 to current date. A list of python versions with its released date is given beloy, Python 1.0 January 1994 Python 1.5 December 1997 Python 1.6 September 5, 2000 Python 2.0 October 16, 2000 Python 2.1 April 17, 2001 Python 2.2 December 21, 2001 Python 23 8 "July 29, 2003 oe | Python 2.4 ‘November 30, 2004 Python 2.5 September 19, 2006 Python 2.6 October 1, 2008 Python 2.7 July 3, 2010 12. | Python 3.0 December 3, 2008 13. | Python 3.1 June 27, 2009 14. | Python 3.2 February 20, 2011 15. | Python 3.3 September 29, 2012 March 16, 2014 September 13, 2015 December 23, 2016 June 27, 2018 20. | Python 3.8 October 14, 2019 Key Differences between Python2 and Python3 ‘Whenever two integers are divided. YOU get a float value, always get integer value. The syntax és simpler and ensily | The wyntax of Python? wane “understandable | comparatively diffiewt | understand mw this version, Rules of ordering | Rules of ordering comparison ave | comparisons have been simplified. | very complex | | The mew Range() function In Python2, the xranget) is naed for | introduced to perform iterations. | iterations | | Wahoul be enloed in purenthei|t should be enclosed in mains. | | The value of variables never | The value of he Shobak variable will changes change while using it inside for- ' | top. We Backward compatiitiy | Not ditticult to port python? to | Python version} i aoe backward ; | python 3 butts never reliable. | compatbe with Pthon2 | Many recent developers are creatin Many older libraries created for | libraries which you can only use | Python 2 is not forwaed- compat L with Pythons, COMPARE PYTHON PROGRAMMING LANGUAGE WITH Java Kz PROGRAMMING LANGUAGE deve is @ high level, object-oriented programming language developed by Sun MGcrosystems in 1995. Java runs on many platforms like Windows, Mac OS, and Limax ‘The latest release of Java is Java Standard Edition8. Java works on the principle of ‘smite once run anywhere. Java is object-oriented, platform independent, simple. secure. Robust interpreted, multithread, high performance and dynamic. Python is an object-oriented, high-level and all in one Programming language It wes developed by Guido Van Rossum during 1985-1990. Python is highly readable and easily understandable. Python uses simple English keywords very often whereas other languages use punctuation. Python is easy to learn, easy to read, interactive mode, Portable, extendable, databases, scalable. Below are the most important Differences between Java vs. Python : * dava language is more about syntax, if one can forget to add curly braces (or) semicolon in the end then this will show error as your output. But there is nothing 'tke that with python there is no need of semicolon and curly braces in the end Dut python follows indentation process so that it will make your code readable. * 4202 programming is statically typed means that one has to explicitly mention the ata type of variable. If datatype (int, float, double, character) does not mention . oie | em é ioe i then the error will occur in program. Python is dynamically typed means One }, to directly assign a value to a variable; at the runtime it will assume data ty, © Java codes are more complex than python codes. If one can write a hello Wor; jprogram in both then you can observe the complexity of the code, 4 lines of ,,. dm Java and same hello world program in python will be of 1-line code. * I -someone works on a project which requires a fast speed then java is the be choice because python is an interpreter and it will assume data type of a Varia} at runtime due to which it becomes slower than java. * Java has JDBC (Java DataBase Connectivity) which is widely used connecti, with different databases like SQL, SQOOP etc., and JDBC is very popular 2 but Pythons database access layers are weaker than Javas JDBC. This is wh rarely used in enterprises. * Java enjoys more undeviating refactoring support than python. Thanks to its sta- type system and universality of IDEs in development. Python has always had : existence in the talent space and has the popularity for many reasons includi- Data Science and DevOps movement. + Java Architecture : JVM (Java Virtual Machine) is an engine that gives runti- environment to operate the Java Code. It turns Java bytecode into machin: language. JVM is a chunk of JRE (Java Run Environment). class file |2™M Output java file FIG 1.16; * Python architecture Python Interpreter translates your source code into machine independent bytecode (.pyc). It stores -Pyc file in __PyCache__ folder. Whe! you run the same program (Without changes) then it will use this bytecode withou translating it again. Byte Code (. pyc) will be shipped to PVM. It executes the code a Fava mL _— = FIG 1.17; | Longer lines of code as compared Python public class Sample | ( Public static void main (String [] | args) | t | ‘System.out.printIn(“Hello World”), } } | ‘Syntax At the end of the statement if you In python, statements do not need miss semicolon it throws an error. a semicolon at the end. In Java you must define particular | In python, you have never seen a | block using curly braces without sight of curly braces but | code won't work. indentation is mandatory in python, Indentation also improves readability of code. | 3. | Dynamic In java you must declare type of __| Python codes are dynamic typed. data. This means that you dont need to | class Example declare the type of the variable { this type of the variable this is known as duck typing. public static void main (String (Jargs)| X = 45 { str = “welcome” int x=10; ‘System.out printin(x); } i 4. | Speed In terms of speed, Java is faster. _| I is slower because python is an Whenever in projects speed matters | interpreter language and also it hence java is best. determines the type of data at runtime, 5. | portability Due to the high popularity of Java, | Python is also portable but in front) JVM (Jaya Virtual Machine) is java, python is not popular. available almost everywhere, (DBC) Java Database Connectivity | Pythons database access layers ar, is most popular and widely used to | weaker than Javas JDBC. This is connect with database. Se eiitiscs, | Easy to uso | Java isnot easy to use as compared to | Python codes are shorter than java python because there is no dynamic | Python follows dynamic programming concept and codes are | progr. 1ming. Python codes not | longer than python. only easy to use but also easy to understand because of indentation 8. | Practical Dexterity| Java enjoys more undeviating Python has always had an refactoring support than python thanks) existence in the talent space and | | to its static type system and | has the popularity for many | universality of IDE’s in development.| reasons including Data science and | ae DevOps movemoment, 9. | Legacy Javas history in the enterprise and its) Python has less legacy problem so slightly more verbose coding style _| organization finds difficulty for the mean that Java legacy systems are _| script to copy and paste codes. typically larger and more numerous than pythons. 17 FEATURES OF PYTHON PROGRAMMING * Easy to Learn : Python is easy to learn and use. Python has relatively few keywords, simple structure and a clearly defined syntax. This allows the student to pick up the language in a relatively short period of time. It is user friendly and high level programming language. Python is very easy to code. Compared to other popular languages like Jé and C++, it is easier to code in Python. Anyone can leam python syntax. Ithas programming and scripting language capabilities : programming is used to deve business logic of the software application. Scripting language is a computer lang with a series of commands with in a file that is cay cen) style capabailities : Python supports Procedure-oriented program well as object-oriented Programming. In procedure-oriented languages, the pro ERT 1 rrr nd Raper me | ‘s Itis open source (not only free but also modifies the existing application): not only free but also modifies the existing application. it can be downloadable from the following link https://www.python.org/downloads: * Case sensitive * Itallows us to install on any OS. (WIT! SETS THE EXECUTION ENVIRONMENT FOR PYTHON Download and Installation Python Software on Windows OS : Step 1 : Go to website www.python.org and click downloads select version which you want. Prue 18 : Step 2 : Click on latest version Python 3.8.1 and download. The file named python- 3.8.1-amd64.exe should start downloading into your standard download folder. After _ download double-click the icon labeling the file python-3.8.1-amd64.exe. A Python 3.8.1(64-1 Setup pop-up window will appear. - Install Python 3.8.1 (32-bit) | Sete sat Now to insta Pinon with det satin. oF crease Contaminata features © insta Now 2 ‘nce pi and decarerabon ‘Coe nonstate aoa FIG 1.19; Ensure that the Install launcher for all users (recommended) and the Add Pytho, 3.8 to PATH checkboxes at the bottom are checked. If the Python Installer finds an earlier version of Python installed on your computer, the Install Now message May instead appear as Upgrade Now (and the checkboxes will not appear). Step 3: Highlight the Install Now (or Upgrade Now) message, and then click i, When run, a User Account Control pop-up window may a; pear on your screen, |; asks, Do you want to allow this app to make changes to your device. Step 4 : Click the Yes button: A new Python 3.8.1 (64-bit) Setup pop-up window will appear with a Setu, Progress message and a progress bar. FIG 1.20: During installation, it will show the various components it is installing and move the progress bar towards completion. Soon, a new Python 3.8.1 (64-bit) Setup pop-4? window will appear with a Setup was successful message er FIG 121: [EMARTERET 0» nro and Raspberry PT Glick the Close button, Python should now be installed Verifying To try to verify installation, 1, Navigate to the directory C:\Users\ ser\ AppData\Local\ Programs\ Python\Python38 (or to whatever directory P thon was installed : see the pop-up window for installing step 3) 2. Double-click the icon/file python.exe The following pop-up window will appear. Bien tenctPopeitontyenteyienee FIG 1.22: Apop-up window with the title C:\Users\user\ AppData\Local\Programs\Python\ Python38\python.exe appears, and inside the window; on the first line is the text Python 388.11... (notice that it should also say 64 bit). Inside the window, at the bottom left, is the prompt >>>: type exit() to this prompt and press enter to terminate Python ‘Setting up PATH to Python : * Programs and other executable files can bein many directories, so operating systems Provide a search path that lists the directories that the OS searches for executable. * The path is stored in an environment variable, which is a named string maintained by the operating system, This variable contains information available to the command shell and other programs * Copy the Python installation location C:\Users\user\AppData\Local\ Programs\Python\Python38, FIG 1.23 Right-click the My Computer icon on your desktop and choose Propert. then select Advanced System properties. » if FIG 1.24: * Goto Environment Variables and go to System Variables select Path Edit. FIG 1.25: lopy the location C:\Users\user\AppData\Local\Programs\ Python \Python38 and ick OK. ray Hitt i i i a Fl FIG 1.26: Oe visces SCRIPT (COMMAND PROMPT, SCRIPT AND IDE) IN DIFFERENT WAYS Python IDLE : E IDLE---- IDLE short form for Integrated Development Environment or Integrated Development and Learning. it is built -in tool and it is graphical user support tool and which is allowing us to write and execute the program.3) Using IDE: (Integrated Development Environment). IDLE is a development environment for Python Programming. An IDE combines a program editor and a language environment as a convenience to the programmer. You can execute your Python code using a Graphical User Interface (GUI). IDE and CUI are tools. (which can't use for unit test in other languages like C.C++, lack of features) so we are going for third party IDE’S. All you need to do is : Click on Start button -> go to -> All Programs ->go to -> Python -> go to-> IDLE (Python GUI) ‘ee Ie 018, BaHTINNG) BE ‘melo, “oopyrighe®, “oredica™ or "License()* for more FIG 1.27; Third Party IDE’S : * pycham * pydev * anaconda python (jupyter/note book) * eclipse for python * wings IDE * komedo IDE * process of running script: Click on Start button -> go to -> All Programs ->go to -> Python -> go to-> jp (Python GUI) .python shell will be opened . Go to File menu click on New File (CTRL+N) and write the code and save -Py extension .example (1.py) FIG 1.28 And run the program by Pressing F5 (or) RunaRun Module. Output can be observed after Run.

You might also like