The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by Education Technology, 2023-09-05 05:09:26

Class 7

3rd Edition

Keywords: computing e-book 7

All About Cloud Google Maps on Phone Places Option 1. On your Android phone or tablet, open the Google Maps app. 2. Search for a place or tap it on the map. 3. In the bottom left, tap Directions. If you touch and hold the button instead, you’ll start navigation and can skip steps 4-6. 4. Optional: To add additional destinations, go to the top right and tap More and then Add stop. You can add up to 9 stops. When you are finished, tap Done. 5. Choose one of the following: • Driving: • Transit: • Walking: • Rides: • Cycling: 6. If other routes are available, they will be shown in gray on the map. To follow an alternate route, tap the gray line. 7. To start navigation, tap Start Start. If you see searching for GPS, your phone is trying to get a GPS signal. For example, you might be in or near a tunnel, parking garage, or other location where there’s no GPS signal. 8. To stop or cancel navigation, go to the bottom left and tap Close Close. After selecting anyplace in google maps we can start navigation by selecting the Directions option, Save that place, Search Nearby places to that location, send that place to your phone (in case of desktop usage) and we can also share the location via URL. The City School 101 2023-2024


Google Coordinates Details on Maps After selecting anyplace in google maps we can start navigation by selecting the Directions option, Save that place, Search Nearby places to that location, send that place to your phone (in case of desktop usage) and we can also share the location via URL. 1. Open the Google maps and locate my house on maps by clicking or manually locate my house using the nearest landmark. 2. Click on location it will show me a dialogue box in the bottom with address and coordinates 24.818294, 67.070234 3. Share these coordinates to anyone to locate a place on the entire planet. In google maps there are several other useful information about that place is available at the bottom of the left pane like address, website, phone number, working hours, photos, etc. We can also contribute to this content by adding photos or “Suggest an edit” option. If we scroll down a little more, we can see a public review option along with the 5-star rating system which describes the place more in detail. We can also add our review as per our experience. The City School 102 2023-2024


1. A network, in computing, is a group of two or more devices that can communicate. 2. Network Topology is the schematic description of a network arrangement, connecting various nodes (sender and receiver) through lines of connection. 3. LAN, MAN and WAN are the three major types of the network designed to operate over the area they cover. 4. Wi-Fi Protected Access (WPA), Wi-Fi Protected Access II (WPA2), and Wi-Fi Protected Access 3 (WPA3) are three security protocols and security certification programs developed by the Wi-Fi Alliance to secure wireless computer networks. 5. Intellectual property includes intangible creations of the human intellect. 6. Personal data, also known as personal information, personally identifying information (PII), or Sensitive Personal Information (SPI) is any information relating to identifying a person. 7. Intellectual property includes copyright, patents, trademarks, industrial design rights, plant variety rights etc. 8. Google Drive allows users to store files on their servers, synchronize files across devices, and share files. 9. Google Translate is a free multilingual machine translation service developed by Google, to translate text 10. Google Maps is a web-based service that provides detailed information about geographical regions and sites around the world. Let’s Review My Notes! The City School 103 2023-2024


Presentation Design Do’s and Dont’s 1. Your information, design and style should be based on what your audience will understand and respond to 2. Use minimal text and more images. Images increase retention by 42% 3. Use a single color in your selected palette to emphasize important points in your text 4. Titles should be at least 28 to 48 points, bulleted text or body copy at least 24 points. Only use caps in headlines and section titles, not in paragraphs 1. Don’t use pixelated, blurry, or tiny images 2. Don’t tell your data when you can show it; Visualize your data wherever possible 3. Use too many graphics; they can distract the audience from your content 4. Using too many borders, boxes, lines, arrows, and spaces can be distracting Do’s Dont’s


Student Learning Outcomes ISTE Student Standard Coverage 1. Manage content creation without investing too much effort on content layout and formatting. 2. Insert, edit and format content via storyline feature. 3. Organize content in sequential order. 4. Add a title to Sway. 5. Add content such as text, images and videos to Sway from local drive or web. 6. Preview sway. 7. Change the style of Sway. 8. Share Sway with teacher and peers. After going through this chapter, students will be able to: Empowered Learner Creative Communicator Knowledge Constructor 1a 1c 1d 6a 6b 6d Global Collaborator 3c 7b Presenting Your Ideas


Sway is a new app from Microsoft Office that makes it easy to create and share interactive reports, personal stories, presentations, and more. Start by adding your text and pictures, search for and import relevant content from other sources, and then watch Sway do the rest. With Sway, you’re no longer limited to picking a pre-designed template that makes your presentations look like everyone else’s, and you don’t have to have any design skills to transform and showcase information in modern, interactive, and attention-getting ways. With Sway, there’s no need to spend lots of time on formatting. Its built-in design engine takes care of making your creation look its best. If the initial design doesn’t quite match your taste or mood, you can easily apply another — or fully customize your layout to make it your own. It’s super easy to share your finished Sways. Family, friends, classmates, and coworkers can see your creations on the Web without signing up, signing in, or downloading anything. And you can change the privacy settings for any Sway whenever you want more control over what you share. 4.1. What is Sway? 4.2. What Can I Create with Sway? S Whether it’s a report, a presentation, a newsletter, a personal story, a photo album, or a visual trip report, there’s virtually no limit on what you can express creatively with Sway. fi Reports Newsletter Presentation Stories The City School 106 2023-2024


Presenting Your Ideas 4.3. Getting Started with MS Sway Sign-in to Start Creating 1. To get started with Sway, 2. Visit sway.office.com in any browser and then click Sign in on the top menu bar. 3. When prompted, enter the email address you want to use with Sway. 4. You can use your free Microsoft Account (Hotmail, Outlook.com) or any organizational account given to you by your work or school. 5. If you don’t already have an account, visit www.microsoft.com/account to sign up for free. Create On the My Sways page that opens after you’ve signed in, click or tap Create New to start creating your first Sway. The City School 107 2023-2024


Get to Know Your Storyline The Storyline is where you type, insert, edit, and format the content that tells your story. Content is arranged in sequential order by adding cards, each of which holds the type of content you want — such as text, images, videos, and even Office documents. The order of cards can be rearranged at any time to suit your needs. Give Your Sway a Title Click the Title your Sway placeholder text shown in the first card on the Storyline, and then type a short but meaningful description of what your Sway is all about. When you later share your finished Sway, this title will be the first thing that others will see. Add Images and Text to Sway To add content to your Sway, such as text, images, or videos, click or tap the + icon at the bottom of any existing card. You can also drag and drop text and images right onto your Storyline. (Don’t hesitate to experiment — you can change the order of your content at any time and customize each card the way you want.) The City School 108 2023-2024


Presenting Your Ideas Add Content to Your Sway You can easily search for and add additional content to your Sway, such as an image that is stored on your computer or mobile device. Sway can also search the Web for the most relevant content, such as videos, and add it to your Sway. On the menu bar, click Insert, select your preferred content source from the menu, and then enter any search keyword or phrase into the Search Sources box. Preview Your Sway You can preview your work in progress at any time by clicking the Design tab. When you preview your Sway, you can see how it will appear to others when you later decide to share it. To fully experience your Sway, click the Play button on the top menu bar. To return to your Storyline when you’re done previewing your Sway, click the Storyline tab. Sway or PowerPoint? S PowerPoint is primarlity used for presenting charts and graphs and when a dedicated person is presenting the content. Sway is preferred choice of tool when information is simply consumed by the end user without a live presentation The City School 109 2023-2024


Let’s Review 1. MS Sway allows to create and share interactive reports, presentations, personal stories, newsletters and much more. 2. Storyline is where you type, insert, edit and format the content. 3. Title of your Sway is the first thing others see when you share your Sway. 4. Content is arranged in sequential order by adding cards. 5. To add content to your Sway, such as text, images, or videos, click or tap the + icon at the bottom of any existing card. 6. The Design tab allows you to view your work in progress at any time. 7. The Play button on the top to full experience your sway. My Notes! The City School 110 2023-2024


According to Code.org, 71% of all new STEM (jobs are in computing. Learning how to code will give your child a head start in the real world. Future Demand When children learn how to code they do not only consume digital media and technology but create it. Creativity skill Learning how to code improves logical communication and strengths in both verbal and written skills. Communication skill By coding, children can develop their own games, website, apps and much more. They actually build their own dreams and desires! Coding is fun Why You Should Learn to Code?


Student Learning Outcomes ISTE Student Standard Coverage 1. Process and convert an algorithm into a flowchart. 2. Create solution steps using pseudo-codes. 3. Understand the concept of a computer program. 4. Understand that the program interacts with hardware. 5. Familiarize with Python programming language and user interface of Python IDLE 6. Work with basic commands of python such as print, input, comments, and calculation with numbers, list and delete 7. Understand and work with conditional and looping structures in Python 8. Create robust programs by using functions in Python 9. Create shapes and graphics through programming 10. Create dynamic programs through user actions and event handling 11. Debug program by identifying logical and syntax errors After going through this chapter, students will be able to: Empowered Learner Creative Communicator Computational Thinker 1a 1d 5c 5d 6d Programming the Computer-Python


5.1. Overview 5.2. Flowcharts and Algorithms Algorithms Computer programming is a way of giving computers instructions about what they should do next. These instructions are known as code, and computer programmers write code to solve problems or perform a task. The end goal is to create something: that could mean anything from a web page, or a piece of software, or even just a pretty picture. That’s why computer programming is often described as a mix of art and science; it’s technical and analytical, yet creative at the same time. Algorithms and flowcharts are two different tools used for creating new programs, especially in computer programming. An algorithm is a step-by-step analysis of the process, while a flowchart explains the steps of a program in a graphical way. To write a logical step-by-step method to solve the problem is called an algorithm. In other words, an algorithm is a procedure for solving problems. In order to solve a mathematical or computer problem, this is the first step of the procedure. An algorithm includes calculations, reasoning and data processing. Algorithms can be presented by natural languages, pseudocode and flowcharts, etc. Making a PB&J Sandwich get out two slices of bread spread jelly on one slice spread peanut butter on the other put the slices together undo the twist tie place them on a plate open the jelly jar scoop them out with a knife wipe off the knife set the knife down pickup each of the slices keep the dry sides on the outside place the sandwich back down pick the knife back up again cut the sandwich into two halves open the peanut butter jar scoop some out with a knife get out two slices of bread The City School 113 2023-2024Programming the Computer-Python The City School


Flow Charts Flow Chart Symbols Terminal Flow Lines Input/Output Process Decision A flowchart is a type of diagram that represents an algorithm, workflow or process. The flowchart shows the steps as boxes of various kinds, and their order by connecting the boxes with arrows. Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields. The rounded rectangles, or terminal points, indicate the flowchart’s starting and ending points. The default flow is left to right and top to bottom (the same way you read English). To save time arrowheads are often only drawn when the flow lines go contrary the normal. The parallelograms designate input or output operations. The rectangle depicts a process such as a mathematical computation, or a variable assignment. The diamond is used to represent the true/false statement being tested in a decision symbol. The City School 114 2023-2024


Programming the Computer-Python Example Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a normal programming language but is intended for human reading rather than machine reading. Pseudocode typically omits details that are essential for machine understanding of the algorithm, such as variable declarations, system specific code etc. In simple words, Pseudocode is a precise form of an algorithm without unnecessary steps of vocabulary/ words. Start End Read temperature temperature<32 Print Above freezing Print Below freezing 5.3. Pseudocode Pseucode Example BEGIN input hours input rate pay=hours*rate print pay END The City School 115 2023-2024


5.4. What is a Program 5.5. Getting Started with Python How a Program Interacts with Hardware In computing, a program is a specific set of ordered operations for a computer to perform. In the modern computer that John von Neumann outlined in 1945, the program contains a one-at-atime sequence of instructions that the computer follows. Hardware is a term we use to describe the electronics and mechanical parts of the computer. To be able to use it, we need programs, the software. A computer program is a list of instructions stored as a file on a storage device. If this program is embedded inside a hardware device it is called firmware. When we run the program, the computer reads the list of commands or instructions and does what the program tells it to do. Python is a high-level programming language designed to be easy to read and simple to implement. It is open-source, which means it is free to use, even for commercial applications. Python can run on Mac, Windows, and Unix systems. Python is considered a scripting language, like Ruby or Perl and is often used for creating Web applications and dynamic Web content. {Code} Programming Language v/s Scripting Language Programming languages work with full-length code and are capable of running independently while a scripting language generally runs on small chunks of code and needs embedding into parent programs. The City School 116 2023-2024


Programming the Computer-Python Python IDLE There are tens of thousands of famous python websites on the internet, few of them are listed: Uber Spotify Netflix Pinterest Amazon Reddit Dropbox Google Python is a Programming language is popular because of its easy syntax. We will start writing some code in PYTHON IDLE (Integrated Development and Learning Environment). File menu: it is for basic operations like opening, saving and printing programs. Shell menu: it is to reset the environment Debug menu: it is to check your program from any errors The City School 117 2023-2024


Writing your First Program in Python 4. Run the program from the Run menu or press Ctrl+F5. 1. Open File menu and select New File or press Ctrl+N. 3. Open File menu and save the program or press Ctrl+S. 2. Type print (“My first program in Python”). The City School 118 2023-2024


Programming the Computer-Python Python Indentations Indentation refers to the spaces at the beginning of a code line. Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. Python uses indentation to indicate a block of code. Indentation Example if 5 > 2 print (”Five is greater than two”) 5.6. Variables and Data Types A variable is nothing but a name given to a storage area that our programs can manipulate. A variable is a container of data in a computer’s memory where the computer stores the different types of data and this could be numeric or text. To create and access these Variable (data containers) we name them so we can call them in our program where it is necessary. Data can be of any type like text, numbers, integers, etc. A variable can store values only in one data type either it could be numeric or string. Python has no command for declaring a variable. Numeric data type: This data type is used to hold numeric values like integers, or Float like decimal numbers. String data type: The string is a sequence of characters like a simple text “Hello World”. Python supports Unicode characters. Generally, strings are represented by either single or double- “a” 4 2.5 “hello” Comments in Python #this is comment print(”hello world”) The City School 119 2023-2024


Example Variable Names Assign Value to Multiple Variables A variable can have a short name (like x and y) or a more descriptive name (age, car_ name, total_volume). Rules for Python variables: • A variable name must start with a letter or the underscore character • A variable name cannot start with a number • A variable name can only contain alpha-numeric characters and underscores(A-z, 0-9, and _ ) • Variable names are case-sensitive (age, Age and AGE are three different variables) Python allows us to assign values to multiple variables in one line: quotes. In Python variables are created the moment we assign a value to it. Unlike other programming languages, Python has no command for declaring a variable. A variable is created the moment we first assign a value to it. The City School 120 2023-2024


Programming the Computer-Python 5.7. Comments Output Variables Python has the ability to add comments for the purpose of in-code documentation. In other words, comments are just a dead piece of code which can be used for our references only. Comments start with a #, and Python will render the rest of the line as a comment. Comments in Python #this is comment print(”hello world”) The Python print statement is often used to output variables. To combine both text and a variable, Python uses the + character: We can also use the + character to add a variable to another variable: The City School 121 2023-2024


5.8. Python Numbers Type Conversion There are three numeric types in Python: • Integer: also known as int, is a whole number, positive or negative, without decimals, of unlimited length. • float: also known as floating point number, is a number, positive or negative, containing one or more decimals. • complex: are written with a “j” as the imaginary part Variables of numeric types are created when we assign a value to them. To verify the type of any object in Python, use the type() function. A sample code that determines type is shown below: We can convert from one type to another with the int()and float() methods. A sample code is shown below: Python Numbers x=1 #int y=2.8 #float z=1j #complex The City School 122 2023-2024


Programming the Computer-Python 5.9. Calculation with Numbers Sample Code We can also use Python to do any kind of calculation: addition, subtraction, multiplication, division, etc. The rules that we have learned in Microsoft Excel for the use of parentheses apply here, too. For example, let’s suppose that we want to display the term percentage of a student for a subject by using averages in exam marks and course work. Multiplications and divisions are calculated before additions and subtractions. This means that 4+2*5 gives you 14 and not 30. Use parentheses to prioritize the sequence of calculations. For this example, we will also look into the user interaction using INPUT feature of python to take data from the user end. 1. In this example, the first line is having a comment 2. In the 2nd line, we have declared a variable named subject with user input to take subject name form user. 3. In the 3rd line, we have declared a variable name exam while setting its data type to float. 4. In the 3rd line, we have declared a variable for course work with the name of CW while setting its data type to float. 5. In the 5th line, we declare the variable name Percentage while setting its value to a mathematical calculation of exam+cw divided by 2 to get the average percentage of the subject. 6. In the 6th line, we have printed the string value along with the values of the subject variable and percentage variable. #calculate the percentage of a subject subject=(input(“enter the subject name: “)) exam= float(input(“enter the marks obtained in exam”)) CW=float(input(“enter the marks obtained in coursework”)) percentage=(exam+CW)/2 print(“The average percentage of: “, subject,”:”,percentage) The City School 123 2023-2024


5.10. LIST in Python Deleting an Item from List Adding an Item to the List In Python, you can store your data into variables, but you can also put them in lists. A list is just an ordered collection of items which can be of any data type. Creating a list is as simple as putting different comma-separated values between square brackets. Each element of a list is assigned a value by using an index. An example of a list could be: NewList=[10,20,30,”Samsung”] To call a list element is very easy as calling a cell reference in excel: print(NewList[3]). By this code, pythons output will be Samsung, as the count in the list starts from 0. Del command is used to delete a list element as mentioned in the example below To add an item to the end of the list, use the append() method Checkpoint Algorithms can be presented by natural languages, pseudocode and flowcharts Hardware is a term we use to describe the electronics and mechanical parts of the computer. Comments are used for the purpose of in-code documentation. The City School 124 2023-2024


Programming the Computer-Python 5.11. Conditional Statements in Python Conditional statement is a set of rules performed if a certain condition is met. IF statement is a programming conditional statement that, if proved true, performs a function or displays information. An if statement in python is written by using the IF keyword. The sample code below shows the if statement in python. In this example, we use two variables, a and b, which are used as part of the if statement to test whether b is greater than a. As a is 33, and b is 200, we know that 200 is greater than 33, and so we print to screen that “b is greater than a”. Indentation is necessary; if we do not use the indentation as mentioned in example, python will give an error. The ELIF keyword is Python’s way of saying if the previous conditions were not true, then try this condition. The sample code below demonstrates Elif statement. # This program compares two numbers using if a = 33 b = 200 # if block if b > a: print(“b is greater than a”) IF Statement ELIF Statement Sample Code The City School 125 2023-2024


Sample Code Sample Code # This program compares two numbers using elif a = 33 b = 200 # if block if b > a: print(“b is greater than a”) # elif block elif b = = a: print(“a and b are equal”) # This program compares two numbers using else statements a = 33 b = 200 # if block if b > a: print(“b is greater than a”) # elif block elif b == a: print(“a and b are equal”) # else block else print(“a is greater than b”) In this example a is equal to b, so the first condition is not true, but the elif condition is true, so we print to screen that “a and b are equal”. The else keyword catches anything which isn’t caught by the preceding conditions. The sample code below shows else statement. Else Statement The City School 126 2023-2024


Programming the Computer-Python Sample Code # This defines a list of student marks stdMarks = [70, 80, 92.5, 60.2] # This variable keeps track of the max marks maxMarks = 0 # for loop block for i in range(0,4): if stdMarks[i] > maxMarks: maxMarks = stdMarks[i] # Prints highest student marks print(“highest marks are: “, maxMarks) In this example a is greater than b, so the first condition is not true, also the elif condition is not true, so we go to the else condition and print to screen that “a is greater than b”. We can also use the else without using elif. A For loop is used for repeating over a sequence (that is either a list or a string). This is less like the FOR keyword in other programming languages and works more like an iterator method as found in other object-orientated programming languages. For example, we have a list of students and we want to display the student with the highest marks without using the max() function: 5.12. Loops in Python The City School 127 2023-2024


1. In the 1st line of this code, we have created a list StdMrks with four values stored in it. 2. In the 2nd line, we have declared a variable name MaxMarks with an integer value of 0. 3. In the 3rd line, we use for loop while declaring another variable i with the range of four. 4. This means this loop will run 4 times. Every time FOR loop runs, it will increase the value of the i variable. 5. In the 4th line, we have set a condition to check that if StdMrks[i] variable is greater than MaxMrks (declared 0 in 2nd line) variable then change the value of MaxMarks[i] to StdMrks value. (StdMrks[i] variable is going to change its value every time the loop runs and change the index of StdMrks. This process is also known as unary increment). Using indention is compulsory or python will not consider the For loop elements and give an error. 6. In the 5th line, MaxMrks is setting its value equal to the current value of StdMarks only if the condition in the previous line is true. 7. In the 6th line, we have just printed the value of MaxMrks along with a string sentence. 5.13. Functions in Python In Python, a function is a group of related statements that perform a specific task. Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable. Furthermore, it avoids repetition and makes code reusable. Function names cannot have spaces in between. Instead of spaces use _ underscore to connect the words. In Python, a function is defined using the def keyword and for executing the function we can use the function name along with parentheses (). The City School 128 2023-2024


Programming the Computer-Python 1. Keyword def marks the start of function header. 2. A function name to uniquely identify it. Function naming follows the same rules of writing identifiers in Python. 3. Parameters (arguments) through which we pass values to a function. They are optional. 4. A colon (:) to mark the end of function header. 5. The last line executes the function, we can call or use the function in our code wherever it is needed. We have already experienced this code earlier but now we have converted the same into a function and now it can be recalled and reused whenever required in the program. Sample Code-1 Sample Code-2 Sample Code-3 # This declares the function called my_function() def my_function(): print(“Hello from a function”) # Calling the function my_function() # This declares the function called print_name() def print_name(): print(“Enter your name”) yourName=input() print(“Hi ”+yourName) # Calling the function print_name() The sample code below demonstrates how functions are used in python: The City School 129 2023-2024


# This declares the function called my_function() def getMarks(): Subject=(input(“Enter the subject name:”)) Exam=float(input(“Enter the marks obtained in the Exam:”)) CW=float(input(“Enter the marks obtained in the course work:”)) Percentage= (Exam+CW)/2 print(“The Average Percentage of”, Subject,”:”, Percentage) # Calling the function getMarks() 5.14. Error Handling in Python A software bug is a coding error that causes an unexpected defect in a computer program. In other words, if a program does not perform as intended, it is most likely because of a bug. There are bugs in software due to unclear or constantly changing requirements, software complexity, programming errors, timelines, errors in bug tracking, communication gap, documentation errors, deviation from standards etc. There are two types of errors/bug in python or any other programming language. Syntax Error: errors in typing the commands and variables. Syntax errors will be automatically detected by the Python IDLE and will show you the error in a dialogue box with a suggested solution or the line number where the mistake has been done: Checkpoint A list is just an ordered collection of items which can be of any data type. IF statement is a programming conditional statement that, if proved true, performs a function or displays information. The City School 130 2023-2024


Programming the Computer-Python 5.15. Creating Graphics with Python Logical Error: a logical mistake while designing the program which occurs due to the improper planning of the program flow. Logical errors can be avoided by working on a Data Flow Diagram (DFD), one practice of DFD is also a flowchart which is an extract of the algorithm. Mentioned below are the few areas which can be used to avoid logical errors in your program: The Canvas widget supplies graphics facilities for Tkinter. Among these graphical objects are lines, circles, images, and even other widgets. With this widget, it’s possible to draw graphs and plots, create graphics editors, and implement various kinds of custom widgets and for using those we need to call/import the library of Tkinter so we can use these functions. Form a hypothesis or two before looking at code. • Resolve syntax errors. • Start the debugger. • Identify key variables or conditions. • Step to your suspicious code. • Look at the relevant variables. • Predict what the suspicious line should do. • Compare your expectations with reality. • Think about your logic. Example-Creating Line We will draw our first example, drawing a line. The method create_line(coords, options) is used to draw a straight line. The coordinates “coords” are given as four integer numbers: x1, y1, x2, y2 this means that the line goes from the point (x1, y1) to the point (x2, y2). The City School 131 2023-2024


For creating rectangles, we have the method create_rectangle(coords, options). Coords are again defined by two points, but this time the first one is the top left point and the bottom right point of the rectangle. from tkinter import* master=Tk() canvas_width=80 canvas_height=40 w=Canvas(master, width=canvas_ width,height=canvas_height) w.pack() y=int(canvas_height/2) w.create_line(0,y,canvas_width,y,fill=”#476042”) mainloop() from tkinter import* master=Tk() w=Canvas(master, width=200, height=100) w.pack() w.create_ rectangle(50,20,150,80,fill=”#470642”) w.create_rectangle(65,35,135,65,fill=”yellow”) w.create_line(0,0,50,20,fill=”#470642”,width=3) w.create_line(0,100,50,80,fill=”#470642”,width=3) w.create_line(150,20,200,0,fill=”#470642”,width=3) w.create_line(150,80,200,100,fill=”#470642”,width=3) mainloop() Sample Code-Creating Rectangle The City School 132 2023-2024


Programming the Computer-Python The following image with the coordinates will simplify the understanding of the application of create_lines and create_rectangle in our previous example. We can create an oval on a canvas c with the method id = C.create_oval (x0, y0, x1, y1, option, ... ) This method returns the object ID of the new oval object on the canvas C. The following script draws a circle around the point (50,50) with the radius 100: from tkinter import* canvas_width=190 canvas_height=150 master=Tk() w=Canvas(master, width=canvas_width, height=canvas_height) w.pack() w.create_oval(50,50,100,100) mainloop() Sample Code-Creating Oval As per Code.org, there are over 500,000 openings for computing jobs in the USA. The City School 133 2023-2024


5.16. Event Handling in Python Events in python are more likely we have in other programming languages. They also execute at any specific action/signal occurred for i.e. hovering a mouse at a certain point, clicks of the mouse either right click or left click and so on. A Tkinter application runs most of its time inside an event loop, which is entered via the mainloop method. It waits for events to happen. Events can be key presses or mouse operations by the user. Tkinter provides a mechanism to let the programmer deal with events. For each widget, it’s possible to bind Python functions and methods to an event. widget.bind(event, handler) If the defined event occurs in the widget, the handler function is called with an event object, describing the event. In this program, the event will be triggered by clicking on the Tkinter widget window. If we click once it will say “Single Click, Button-1” as defined in string values and if we double click it will say “Double click, so let’s stop as defined in a string value. Sample Code-1 from tkinter import* def hello (event): print(“Single click, Button-1”) def quit(event): print(“Double click, so let’s stop”) import sys;sys.exit() widget=Button(None,text=’Mouse Clicks’) widget.pack() widget.bind(‘<Button-1>’,hello) widget.bind(‘<Double-1>’,quit) widget.mainloop() The City School 134 2023-2024


Programming the Computer-Python Let’s have another simple example, which shows how to use the motion event, i.e. if the mouse is moved inside of a widget: Every time we move the mouse in the Message widget, the position of the mouse pointer will be printed. When we leave this widget, the function motion() is not called anymore. Basic colour list plot for python. There are more colours which can be used with basic words like forest green or lime etc. Sample Code-2 from tkinter import* def motion(event): print(“Mouse position:(%s %s)” % (event.x,event.y)) return master=Tk() whatever_you_do=”Expect the best, Prepare for the worst.\n Mohammad Ali jinnah” msg=Message(master,text=whatever you do) msg.config(bg=’lightgreen’,font=(‘times’,24,’italic’)) msg.bind(‘<Motion>’,motion) msg.pack() mainloop() Color Codes in Python gray brown orange olive blue purple red green cyan The City School 135 2023-2024


1. Algorithms can be presented by natural languages, pseudocode and flowcharts, etc. 2. A flowchart is a type of diagram that represents an algorithm, workflow or process. 3. Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm 4. A program is a specific set of ordered operations for a computer to perform 5. Python is a high-level programming language designed to be easy to read and simple to implement. 6. Indentation refers to the spaces at the beginning of a code line. 7. A variable is a name given to a storage area that our programs can manipulate. 8. A list is just an ordered collection of items. 9. For loop is used for repeating over a sequence. 10. Conditional statement is a set of rules performed if a certain condition is met. 11. A function is a group of related statements that perform a specific task. 12. A software bug is a coding error that causes an unexpected defect in a computer program. 13. Syntax errors in typing the commands and variables. 14. A logical mistake while designing the program which occurs due to the improper planning of the program flow is called logical error. Let’s Review My Notes!! The City School 136 2023-2024


S T E M Science Technology Engineering Mathematics Did you know, STEM workers earn 26 percent MORE than those without a STEM background Importance of STEM Education Computer occupation STEM related mgmt Life and physical science technicians STEM related sales Engineers 17% 1,083,800 510,900 167,600 150,900 118,400 9.8% STEM Employment Non-STEM Employment Projected Job Growth Projected Job Openings


Student Learning Outcomes ISTE Student Standard Coverage 1. Familiarize with robotics and understand its importance 2. Familiarize with Edison robot and its working 3. Understand the EdPy App interface and create an online account 4. Understand Edison drive function with EdPy 5. Creating a square and circle using Edison 6. Work with loops and conditional structures in EdPy 7. Familiarize with obstacle detection programs in Edison 8. Familiarize with clap control drive and line tracking sensors in Edison After going through this chapter, students will be able to: Empowered Learner Creative Communicator Computational Thinkiner Innovative Designer 1a 1d 4d 5c 5d 6d Robotics


6.1. What is Robotics Robotics is a branch of engineering that involves the conception, design, manufacture, and operation of robots. This field overlaps with electronics, computer science, artificial intelligence, mechatronics, nanotechnology and bioengineering. Whenever the word ROBOTICS is used, we think of a machine which would have metal arms, legs, bionic eyes and the robotic voice. This machine is called a humanoid or android. Robotics is all about automation of any process or task. A robot can contain numerous electronic or non-electronic parts like motors, battery, chassis, wirings, sensors, computer boards for programming etc. Science-fiction author Isaac Asimov is often given credit for being the first person to use the term robotics in a short story composed in the 1940s. In the story, Asimov suggested three principles to guide the behaviour of robots and smart machines. Asimov’s Three Laws of Robotics, as they are called, have survived to the present: • Robots must never harm human beings. • Robots must follow instructions from humans without violating rule 1. • Robots must protect themselves without violating the other rules </> Why Robotics is Important? Robots make our life easier and much safer Robots can do tasks which are dangerous for humans like bomb diffusion, security guard, and Mars rover etc. Besides these dangerous tasks, robots can perform tasks which humans are not good at such as: The City School 139 2023-2024Robotics The City School


Safety: safety is the most obvious advantage of utilizing robotics. Heavy machinery, machinery that runs at high temperatures, and sharp objects can easily injure a human being. By delegating dangerous tasks to a robot, we can avoid human accidents. Speed, consistency & Production: robots don’t get distracted or need to take breaks. They don’t request vacation time or ask to leave an hour early. A robot will never feel stressed out and start running slower. They also don’t need to be invited to employee meetings or training session. Robots can work all the time, and this speeds up production. Robots never need to divide their attention between a multitude of things. Their work is never contingent on the work of other people. They won’t have unexpected emergencies, and they won’t need to be relocated to complete a different time-sensitive task. They’re always there, and they’re doing what they’re supposed to do. Automation is typically far more reliable than human labour. Perfection & Accuracy: robots will always deliver quality. Since they’re programmed for precise, repetitive motion, they’re less likely to make mistakes. In some ways, robots are simultaneously an employee and a quality control system. A lack of quirks and preferences, combined with the eliminated possibility of human error and the outcomes are more accurate than the humans. Job Creation: robots don’t take jobs away. They merely change the jobs that exist. Robots need people for monitoring and supervision. The more robots we need, the more people we’ll need to build those robots. By training your employees to work with robots, you’re giving them a reason to stay motivated in their position with your company. They’ll be there for the advancements and they’ll have the unique opportunity to develop a new set of tech or engineering-related skills. The City School 140 2023-2024


Robotics Robotics Industry Robots are becoming increasingly prevalent in almost every industry, from healthcare and manufacturing to defence and education. Here is the list of the organizations working on robotics as life essentials: Sphero: Sphero invented a now world-famous appenabled robotic ball, which is used in classrooms all over the world to teach through play. In addition to the original ball, other products include the Sphero 2.0 and the Sphero Mini as well as app-enabled racing robots named Ollie and Darkside. The company’s Sphero Edu app is a hub for programming its robots and more. GITA: from the Piaggio Group that brought you the Vespa scooter comes Piaggio Fast Forward; a robotics company dedicated to creating lightweight mobility solutions for people and goods. The company’s flagship robot, Gita, is a mobile carrier that follows people around and carries up to 45 pounds. Gita can be used to carry everything from heavy books between classes to groceries. MOXI: Diligent’s AI-enabled robots are designed to work with people in everyday environments. The company’s autonomous “Moxi” robot can be left alone to perform time-consuming logistical tasks in hospitals like setting up patient rooms and restocking supply rooms. Capable of navigating hospital hallways and other tight spaces, Moxi is even imbued with “social intelligence” that’s conveyed through its head movements and LED eyes. The City School 141 2023-2024


Anybots: Equipped with a speaker, camera and video screen, Anybots robots serve as remote avatars that are controlled through a browser-based interface and connect to the Web over Wi-Fi. Say you’re in Chicago and you want to also be in Taiwan. Your robot — which has a built-in guidance system, live video streaming capabilities and is steered with the arrow keys on your computer’s keyboard — can act as a stand-in. ATLAS: Boston Dynamics makes a host of different robots that have human- and animal-like dexterity. A few examples: There’s SpotMini, “a nimble robot that handles objects, climbs stairs, and will operate in offices, homes and outdoors”; Atlas, a “dynamic humanoid” that “uses balance and whole-body skills to achieve twohanded mobile manipulation”; and WildCat, a speedy quadruped that “uses a galloping gait much like a dog or horse and leans into turns to maintain traction and balance.” HV-100: According to Harvest, its HV-100 model was the world’s “first fully autonomous robot that works alongside people in unmodified industrial environments.” Today, more than 30 of them serve major agricultural players across the U.S. to help increase productivity, efficiency and plant quality. Harvest’s robots lessen the load when it comes to manual labour so their human counterparts can focus on other facets of the growing process. The City School 142 2023-2024


Robotics 6.2. Getting Started with Edison Edison robots are a complete STEAM teaching resource designed to bring coding to life. Edison is an expandable robotics system, which works with any LEGO brick compatible building system, the robots can be used as the programmable base for an incredible assortment of engineering and STEM projects. Edison can be programmed through 4 platforms: • Barcodes and Remote Control • EdBlock – Graphical Language • EdScratch – Scratch Language interface • EdPy – Python Programming Interface Edison is equipped with all the sensors, outputs and motors needed to introduce you to the amazing world of robotics. Edison’s creator, Brenton O’Brien says that: a robot is a machine that can behave autonomously which is also a simple definition of robotics. Robotics wouldn’t be possible without electronics. Your Edison robot has electronics which you can see through the transparent top. There are resistors, capacitors, transistors, motors and more. The most important electronic part is Edison’s microcontroller (MCU). The microcontroller is like Edison’s brain. It’s where all the robot’s thinking happens. Edison’s microcontroller is very similar to the processor chip inside a computer, only much smaller. Just like a processor chip in a computer, Edison’s microcontroller contains programs. These programs are what allow Edison to ‘think’ and make decisions. Edison robot is LEGO brick compatible on four of its sides, has a removable skid and two removable wheels and includes a range of built-in sensors. Familiarity with your robot will allow you to create an incredible range of robotics and coding projects. Edison’s sensors, buttons and switches The City School 143 2023-2024


To use Edison, you’re going to need to know where all of Edison’s sensors are located and become familiar with the robot’s three buttons. Turn the Edison robot over to see where the power switch, removable skid, and line tracking sensor are located on the bottom. Edison’s line tracking sensor is made up of two parts: a red LED light and a light sensor. The line tracking sensor also reads special barcodes that activate preinstalled programs. EdPy is Edison’s text-based programming application. The robot is controlled by a program, which contains the instructions and rules governing the robot’s behaviour. Any program you create in EdPy must be downloaded to Edison before the robot can perform the actions. The program can be changed only in the EdPy platform and in such cases, you will need to download the new program to the robot again. To connect Edison with the computer to download the program you create with EdPy, you need the EdComm cable which is Edison’s special cable. The EdComm cable is used to download programs to Edison. It connects into the headphone/audio Socket/jack on your computer or tablet or phone or any other computing device which contains an audio jack and a working web browser to access EdPy app. Default settings of Edison’s three buttons: • Record button 1 press = download program 3 presses = scan barcode • Stop button 1 press = stop program • Play button 1 press = run program Meet Edison Note: Before you begin programming with EdPy you MUST make sure that your computer volume is MAX and it is important that ALL sound enhancements are disabled. This includes Altec Lansing enhancements, Realtek audio enhancements, Beats audio, Spatial sound, and all equalizers. Edison will fail to program if this is not done. The City School 144 2023-2024


Robotics EdPy app is one the web-based programming interface to program Edison. EdPy is a text-based programming language based on Python. Python gives more flexibility to your programs and offers more precise control of your robot. EdPy application can be accessed online and without any installation on your computer or tablet. To access EdPy app. visit https://www.edpyapp.com/ 6.3. Introduction to EdPy EdPy Interface The City School 145 2023-2024


Programming area: this is where you type the Python code to control the Edison robot. Documentation: in this window, you can search the documentation about Python functions that can be used in EdPy. Here you can find explanations of all the available commands including example code. Recently opened: this window contains a list of recently opened programs. Clicking on these will re-open the program in the programming area. Examples: this window contains a list of example programs which you can select and open in the programming area. The example programs explain how to use common functions of the Edison robot, including some to the functions students encountered with the barcode programs. Check code: when the ‘Check Code’ button is clicked, the code in the programming area is checked for errors. If errors are detected, a message will appear in the ‘Compiler Output’ window at the bottom of the screen providing details on the errors. Program: When the ‘Program’ button is clicked, the current program is downloaded to the Edison robot. Make sure the Edison robot is ready for the code by connecting the cable, turning the volume up to full and pressing Edison’s round button one time. Compiler Output: when EdPy translates the written code into commands readable by the Edison robot, this is called ‘compiling the code.’ If errors are detected when you click ‘Check Code,’ they will be displayed in the compiler output section. If there are no errors detected, this section will display a message which reads: ‘There are no errors in your code.’ Line help: the line help is a guide to use while programming which shows users what each of the Python commands do. When you select a line of code in the programming area with your mouse cursor, the ‘line help’ window will display a plain-English description of the command being highlighted by your cursor. This description is a ‘translation’ of the Python code into English. Setup code: All Edison programs must contain the setup code that you see every time you open the EdPy app. The City School 146 2023-2024


Robotics Creating Online EdPy Account Using the online EdPy programming environment you can save your work online and have access to your projects from any browser. All you need to do is to create an account and log in. The online EdPy programming environment can be used with or without an account. Without an account, you don’t have the option to save a project so that you can work on it later. It is highly recommended to work on EdPy while logged into your account so all the work will be available/save for your convenience. The programming area in EdPy has numbered lines. All Edison programs must contain the setup code which is included in lines 1 to 11. When you start a new program, you should start typing on line 13. When you finish writing you should check the program for errors with the Check Code button. If the program has any errors, they appear in the Compiler Output area. Click on Menu and select login. Click on Create Account. Enter details and click on Create Account & Login to proceed. 6.4.Starting to Code in EdPy The City School 147 2023-2024


The following program will turn on the left LED of the robot for 10 seconds. #-------------Setup---------------- import Ed Ed.EdisonVersion = Ed.V2 Ed.DistanceUnits = Ed.CM Ed.Tempo = Ed.TEMPO_MEDIUM #--------Your code below----------- Ed.LeftLed(Ed.ON) Ed.TimeWait(10, Ed.TIME_SECONDS) There is no need to enter the mentioned below code and it will be available always whenever you start a new program, however you can customize the parameters as per your requirement. Import Ed is a predefined code to import the library of Edison functions in python. Ed.EdisonVersion = Ed.V2 is the code to define the version of Edison we are using which is Version 2. Ed.DistanceUnits = Ed.CM is the code to define the unit of measurements to drive the Edison. Ed.Tempo = Ed.TEMPO_MEDIUM is the code to define the music/sound pace. After this line #-------Your code below --------- enter the code to work on Edison. Ed.LeftLed(Ed.ON) is to turn on the left LED of Edison Ed.TimeWait(10, Ed.TIME_SECONDS) is the code where we have defined the interval between the LED to turn on. EdPy works on python and will work with the same rules use for Python like case sensitivity and indentation, therefore you need to be very careful entering the code according to Python style. Sample Code 6.5. Edison Drive Function in EdPy The Edison robot has two motors that allow it to perform a handful of movements. With its two motors, the robot can move forwards and backwards and also spin both left and right. To move your Edison robot you use the drive function, which has three Checkpoint Robotics is important due to its safety, speed, accuracy and consistency Edison robots are a complete STEAM teaching resource designed to bring coding to life. Edison robot has a removable skid and two removable wheels and includes a range of built-in sensors. The City School 148 2023-2024


Robotics #-------------Setup---------------- import Ed Ed.EdisonVersion = Ed.V2 Ed.DistanceUnits = Ed.CM Ed.Tempo = Ed.TEMPO_MEDIUM #--------Your code below----------- Ed.Drive(Ed.FORWARD, Ed.SPEED_4, 9) #-------------Setup---------------- import Ed Ed.EdisonVersion = Ed.V2 Ed.DistanceUnits = Ed.CM Ed.Tempo = Ed.TEMPO_MEDIUM #--------Your code below----------- Ed.Drive(Ed.BACKWARD, Ed.SPEED_3, 7) Sample Code Sample Code Ed.Drive Direction Parameters parameters: direction, speed and distance. The constant Ed.DistanceUnits that is set in the Setup code controls the measurement of distance. There are three distance units: centimetres, written as Ed.CM, inches, written as Ed.INCH and time, written as Ed.TIME. Ed.FORWARD: Edison drives forwards. Ed.BACKWARD: Edison drives backwards. Ed.FORWARD_RIGHT: Edison uses one wheel to turn forwards right (clockwise). Ed.BACKWARD_RIGHT: Edison uses one wheel to turn backwards right (counterclockwise). Ed.FORWARD_LEFT: Edison uses one wheel to turn forwards left (counter-clockwise). Ed.BACKWARD_LEFT: Edison uses one wheel to turn backwards left (clockwise). Ed.SPIN_RIGHT: Edison spins on the spot to the right (clockwise). Ed.SPIN_LEFT: Edison spins on the spot to the left (counter-clockwise). Ed.STOP: Stops Edison immediately. • While entering the code you will observe that a code hint menu will appear, from which we can select the entire code by pressing tab and there would be no need to type the whole code. Using the code hint menu will help you program the code in less time and above all, there will be less chance for syntax errors. • Check the code from Check Code button from the right top corner. • Click on Program Edison button right top corner. • Make sure the Edison is connected to your computer’s headphone jack via the EdComm Cable. Make sure your computer’s volume at maximum and all sound enhancements are disabled. The City School 149 2023-2024


Always remember that while using the Ed.FORWARD and Ed.BACKWARD command, the Distance parameter works as the number of steps(cm/inch) Edison has to move. Whereas, while using Ed.FORWARD_RIGHT, Ed.FORWARD_LEFT, Ed.SPIN_RIGHT, Ed.SPIN_LEFT, the Distance parameter works as the angle at which Edison has to turn. This means that a code like Ed.Drive(Ed.SPIN_LEFT, Ed.SPEED_5, 90) will make the Edison robot turn 90 degrees counterclockwise. A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing. Most important function to use the variable is to have flexibility in the program, rather than entering data directly into a program, we use variables to represent the data. Then, when the program is executed, the variables are replaced with real data. Ed.Drive(Ed.FORWARD, Ed.SPEED_6, 20):This code will drive Edison forward to 20cm at the speed of 6. Ed.Drive(Ed.SPIN_LEFT, Ed.SPEED_6, 90): This code will rotate the Edison to 90 degrees at the speed of 6. #-------------Setup---------------- import Ed Ed.EdisonVersion = Ed.V2 Ed.DistanceUnits = Ed.CM Ed.Tempo = Ed.TEMPO_MEDIUM #--------Your code below----------- Ed.Drive(Ed.FORWARD, Ed.SPEED_6, 20) Ed.Drive(Ed.SPIN_LEFT, Ed.SPEED_6, 90) Ed.Drive(Ed.FORWARD, Ed.SPEED_6, 20) Ed.Drive(Ed.SPIN_LEFT, Ed.SPEED_6, 90) Ed.Drive(Ed.FORWARD, Ed.SPEED_6, 20) Ed.Drive(Ed.SPIN_LEFT, Ed.SPEED_6, 90) Ed.Drive(Ed.FORWARD, Ed.SPEED_6, 20) Sample Code-Creating a Square with Edison 6.6. Variables in Edison The City School 150 2023-2024


Click to View FlipBook Version