Programming

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

After running the following pseudocode, what will the value of VARIABLE be? Set value of VARIABLE to 5 Increase the value of VARIABLE by 3 If the value of VARIABLE is odd, increase its value by 1 If the value of VARIABLE is even, increase its value by 1 If the value of VARIABLE is odd, increase its value by 1

10

How many heading tags are available for heading and subheading when using HTML?

6

You want to have a hyperlink to testout.com on your web page. What is the correct HTML syntax to accomplish this?

<a href="www.testout.com">Link to the TestOut homepage</a>

Which of the following tags contains all the elements that will be presented on the visual portion of a website?

<body></body>

Select the tags you MUST use to have a proper HTML document. (Select three.)

<head> <body> : <html>

Which of the following are the proper HTML tags used to create a numbered list?

<ol> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ol>

A person that can use HTML, CSS, and JavaScript to create websites (as well as service the website and manage user accounts) is known as which of the following?

A full-stack web developer

Application Developer

A person who creates applications for computers and mobile devices. Application Developers are one of the most common careers in programming. Their job is to create applications for computers and mobile devices. They usually work together in teams, and they create all kinds of software: word processors, games, database systems, graphics programs, web browsers, and much more.

Web Developer

A person who creates websites and other technologies that are delivered through the internet. Web developers create websites and other technologies that are delivered through the Internet. For example, the course you're using right now was created by a highly-qualified team of skilled web developers. There are three main types of web development. Frontend developers use HTML, CSS, and JavaScript to create websites. Everything you see when you visit a website was made by a frontend developer. Backend developers do the behind-the-scenes coding that you don't see directly. Databases, user accounts, and security are all part of the backend. Full-stack developers do both frontend and backend work.

QA Engineer

A person who makes sure the quality of a finished software application meets the standards of the company. Companies hire Quality Assurance or QA Engineers to make sure the quality of the finished product meets the standards of the company. Any time a programmer writes code, there are bound to be a few bugs that pop up. Whenever these bugs make it to the end customer, it hurts the company. QA specialists monitor software development in order to maintain a high quality product.

Database Programmer

A person who writes code to design, create, implement, and maintain databases. Database programmers write code to design, create, implement, and maintain databases. Since databases store vital information that must be easily accessible and secure, database programmers are vital for most large companies.

Jessica, a programmer, has created specific statements, including conditional loops to accomplish a task. What has she created?

Algorithm

Which of the following features of an integrated development environment (IDE) BEST allow a programmer to code faster and with less effort? (Select two.)

An IDE can autocomplete key words. An IDE has a library of built-in functions.

You are working on a program that needs to keep track of many values at the same time. Which of the following would you use?

An array

In which of the following careers does one usually work together in teams to create software programs?

Application developer

A software developer wants to add a custom Google Map to a customer's website. Which of the following would the developer use to accomplish this?

Application programming interface (API)

Which programming language type is the most basic human-readable and closest to actual machine language?

Assembly

In object-oriented programming, which of the following concepts is used to describe properties?

Attributes

Databases, authentication, and user accounts are all part of a website's ______________.

Backend

A programmer is creating an application that needs to store a value indicating if the user is logged in or not. Which of the following would be the BEST data type to accomplish this?

Boolean

A user is shopping online and has added two items to the cart. When the user clicks the Checkout button, the shopping cart programming logic checks to see if the user is logged in already. If the user is logged in, the checkout process continues, otherwise, the user is prompted to sign in. Which of the following describes the logical component being used?

Branching

Which of the following logic components is being used and how much is the interest if the amount is 5,000? (Select two.) IF amount < 5,000 THEN interest = 7%, ELSE interest = 8%.

Branching 8%

A software developer wants to provide a compiled executable program to a customer. Which of the following computer languages would provide this capability?

C++

Programming

Computer programming A way of giving computers precise, line-by-line instructions to follow. Computer programming uses programming languages. Programming language A formal language comprising a set of instructions that produce various kinds of output. A compiler converts the high-level programming languages into machine language (ones and zeros). Scripting language A programming language that supports scripts and uses an interpreter that compiles the code line by line at runtime. Pseudocode A way to represent code in a manner that is easier for a wide range of people to understand. Data type An attribute attached to a value that tells the compiler or interpreter how the data should be used. Identifier A user-defined name of a program element, such as a variable or constant. Container A program element, such as an array or vector, that holds a set of values. Function A computer routine or snippet of code that can be reused in a computer program. Object-Oriented Programming (OOP) A programming paradigm based on the concept of objects that can contain both data and programming code. Encapsulation An OOP concept that describes how data and methods are bundled together within one unit or class. Assembly language A human-readable, low-level computer language that is a symbolic representation of binary machine language. Compiled language A computer programming language, such as C and C++, that uses a software tool called a compiler to translate the code into binary machine language. Interpreted language A computer programming language, such as Python, JavaScript, and Ruby, that requires a program called an interpreter to execute the instructions written in the source code each time the application is run. Runtime engine A special interpreter that translates bytecode into computer specific machine language. Bytecode is a platform independent, low-level language that is compiled from source code. Algorithm Specific, step-by-step procedures that illustrate how a problem will be solved. Flowchart A visual representation of the logic in a program.

Programming Language Facts

Computer software is written to tell a computer what to do. These instructions can be written in a variety of programming languages. A program gives step-by-step instructions to the computer. The instructions must be very specific as the computer can only do what it is told. Any part of a programming sequence that is open to variation (like input from a user), must have instructions for possible variations. A flow chart can help with visualizing how each variation and step can flow together. Machine language At their most basic level, computers are machines that respond to physical signals, such as positive and negative electric charges that represent ones and zeros. Processors recognize specific configurations of ones and zeros as commands. This is called machine language. Machine language is extremely difficult for humans to understand. Imagine being a programmer and trying to work with a file with millions of ones and zeros. Even if you knew how to interpret the binary information, it would take you hours just to figure out what the code was supposed to do. Fortunately, modern developers don't have to work directly with machine language. Instead, they use programming languages. These languages make computer instructions much easier for humans to read and write. Assembly language The most basic human-readable computer language is called assembly language. Unlike the other languages, assembly language is closely related to the binary machine language. For example, 1010010101000000000 is a machine language command that tells the processor to store the number 42 to a temporary register. The same command written in assembly language is add ax, 42. Even though assembly language is much easier to understand than machine language, it's cumbersome to write and use, and you'll usually hear about it only in discussions of computer history. However, it is important to note that code written in assembly language is more efficient, meaning it will give you better performance when the code is run. Part of the reason it is more efficient is that assembly language allows direct access to hardware; it is very specific to the processor used as well as other hardware. Compiled languages Compiled programming languages, which include C and C++, use a software tool called a compiler to translate the code into machine language. The source code written in these languages can't be run immediately after it's written. The compiler saves the translation as a file called a binary executable (.exe file). This method has several strengths. Because the executable file is written in machine language, it can go directly to the processor without any additional steps, resulting in fast execution. Another advantage is that these programs have full access to everything on the platform, including cameras, motion sensors, USB-connected devices, and GPS. Because of these advantages, resource-intensive programs such as top-end video games are generally written in compiled languages. Unfortunately, different kinds of computers speak different machine languages. An executable that works on an XBOX won't work on a PlayStation or Nintendo console. To make a compiled program work on multiple platforms, the developer must rewrite and recompile for each platform (a process called porting), which is slow and prone to errors. Additional examples of compiled languages include C#, COBOL, and PASCAL. Interpreted languages Interpreted languages are another solution to making a program work on multiple platforms. These languages include such programs as Python, JavaScript, Ruby, and Perl. Programs written in these languages don't translate source code into binary ahead of time. Instead, a program called an interpreter executes the instructions written in the source code whenever the application is run. Interpreted programs have the advantage of being platform independent. However, they are slower than compiled programs and have limited access to the system's resources. Most applications you access through your web browser, including the labs in this course, are written in interpreted languages. Interpreted languages are also known as scripting languages. In addition to the ones previously listed, many operating systems also include a scripting language to support their own particular operating system, such as Windows PowerShell and Command Prompt, as well as Linux Bash. For example, Windows supports batch files. A batch file contains a collection of commands that are run in sequence for you.Windows PowerShell contains both a command-line shell and the associated scripting language, Windows PowerShell Integrated Scripting Environment (ISE). PowerShell is often used to perform administrative and management tasks. In some cases, these types of tasks can be performed only using a PowerShell script. Another Windows scripting language is Microsoft Visual Basic Scripting Edition (VBScript). VBScript is an active scripting language developed by Microsoft that is modeled on Visual Basic. It allows Microsoft Windows system administrators to generate powerful tools for managing computers with error handling, subroutines, and other advanced programming constructs. It can give the user complete control over many aspects of their computing environment. Runtime engines A subcategory of compiled languages combines the ideas of compiling and interpreting to get many of the advantages of both. Examples include C# and Java. Programs written in these languages follow a two-step process. First, they're compiled into a low-level language called bytecode. When the code is run, a special interpreter called a runtime engine translates the bytecode into that computer's specific machine language. Similar to interpreted languages, bytecode is platform independent. Any computer can run it. The advantage is that bytecode is much easier for the computer to run than an interpreted language. This dramatically improves performance. However, it still runs slower than a fully-compiled executable. Other language categories HyperText Markup Language (HTML) and other markup languages, such as eXtensible Markup Language (XML) are generally not considered to be programming languages. The main purpose of HTML is to tell web browsers how to display static text on the screen. XML uses nested tags to create structure and give meaning to the content within the tags. Another language category includes query languages such as Structured Query Language (SQL) that are used to retrieve information from databases.

Programming Terminology

Computers can perform calculations and manage data, but they can't do anything without instructions. Computer programming is a way of giving computers precise instructions to follow. Programming language Computers can't understand and accept instructions from regular human speech. Instead, they rely on programming languages. Programming languages allow programmers to give the computer precise, line-by-line instructions about what it should do. There are dozens of programming languages, each with its own rules and syntax. Some of the most common languages are C, C++, C#, Python, Java, and JavaScript. Data types A data type is an attribute attached to a value that tells the compiler or interpreter how the data should be used. Each programming language has a slightly different set of data types. The following are a few common data types: Integer is used for whole numbers. These include both positive and negative numbers, as well as zero. Float is used for numbers that have decimal places. It's called float because the computer stores two values behind the scenes: the digits in the number and the location of the decimal point that can float around to any location within the number. Char can store a single text character that uses 1 byte of storage. String is used to store more than one character, such as a word or sentence. Key points are: Strings are used in many programming languages. Specific characters are used to indicate an instruction to the program, such as double quotation marks, ampersand, and backslash. When special characters are needed to communicate their English language meaning within the string they are escaped to let the program understand the way to use the character. For example, in Javascript you put a \ before the character to escape it. The boolean data type consists of two values: True and False. This is especially useful when dealing with things that can be in one of two states, such as a light that can be turned on or off, a door that can be open or shut, or a user that's logged in or logged out. Identifiers In programming, identifiers are used to define names for specific values. The two most common identifiers are: Variables Constants A variable holds a value such as numbers, words, and phrases. Variables can change the values they're holding. Take online banking as an example. To get a checking account balance, the program sends a query to the bank's database, which returns the value of the balance. To keep track of this value, the program uses a variable called checkingBalance. If the balance changes because of a deposit or withdrawal, the program keeps track of the changes by adjusting the value of the checkingBalance variable. Whenever the program needs the checking balance, it calls for the variable. Variables can also store Boolean values. For example: You can create a variable called isLoggedIn, which keeps track of whether the user is signed into the account. When the user logs in, this variable stores the value true. When the user logs out, it changes the variable value to false. A programmer may want to keep track of a value that will never change no matter what. A constant is an identifier that keeps track of values, but unlike a variable, constants can never change. For example: A physicist wants to keep track of the value of pi with fifteen significant figures. Since this value will never change, the physicist uses a constant. The physicist types the name of constant called pi, instead of the long number. Containers Containers are a type of identifier that hold onto a set of values. Two of the most common containers are: Arrays Vectors An array is a special kind of container that can hold onto many values at the same time. In our banking example, the program could query the bank's database to find the user's transaction history. Since there are many values to keep track of, the program uses an array to store them all in a single variable, rather than a separate variable for each value. One of the reasons arrays are so useful is that they are iterable, which means you can use a loop to access all the values one at a time. When the user wants to see the transaction history, the program can use a for loop to display to a list each value in the array. Arrays can also be multidimensional meaning you can have an array of arrays (2-dimensional) or an array of an arrays of arrays (3-dimensional), etc. A table is two-dimensional; a cube is three-dimensional. Multiple columns can be added in a table and it will still be two-dimensional. In the banking example, a 2-dimensional array to find the customers with bank accounts that have kept an average balance over $10,000 for the last 12 months could be formed with the code: declare User(20, 2) as a string The declare statement defines the size of the container or array. Remember that arrays use a 0-based number system, so the second number in the parenthesis indicates three columns in the matrix or table. To populate the rows and columns in the array, the following code could populate the first column with the customers' names, the second column with the customers' account numbers, and the third column with the customers' 12 month average balance. User10kBalance(0,0) = find User and get CustomerName User10kBalance(0,1) = find User and get AccountNumber User10kBalance(0, 2) = find User and get AverageBalance In some programming languages, vectors provide a more dynamic and flexible alternative to arrays. Functions One of the principles of software development is to keep your code DRY (Don't Repeat Yourself). This principle helps to keep the code neat and organized. One way to keep your code DRY is to use functions. Functions are snippets of code that you can write once, then reuse whenever you need them.Functions help you avoid having to copy and paste the code continually. Keep in mind: Functions are named and written separately from the main list of code. When you need to call the function, you type the name of the function followed by open and closed parentheses. Between the parentheses, the code requires arguments or values that will be processed by the function. The function runs, and then delivers return values back to the main list of code. Object-Oriented Programming (OOP) In the early days of computer programming, most programs were a simple list of instructions for the computer to follow. Object-oriented programming is a newer approach where functionality can be divided into smaller groups of actions or tasks. There are two terms that are important to know: classes and objects. A class serves as a prototype, or template, for individual objects in the class. Classes contain properties that are the attributes or characteristics that objects can hold as fields or private variables that other programs cannot change or access directly. Properties can be used as another way to access a field publicly. Classes also contain methods (also known as procedures, functions, routines, or subroutines) that are the behaviors or operations that the object can perform. For example, a method takes input, generates output, and manipulates data. Methods are used to make changes to attributes. Objects are the specific models built from the class templates. These objects work with each other to make the computer program function. Encapsulation Encapsulation is a concept in object-oriented programming that describes how data and methods are bundled together within one unit or class. Encapsulation is also used to prevent unauthorized access to those data and methods. Encapsulation protects certain values by hiding them inside a class. Without encapsulation, a programmer can change any value at any time. With encapsulation, some values are protected from direct editing and can be accessed only by using a class's methods. This ensures that data is accessed and changed in the intended way.

Which of the following is a programming identifier that would be used to define values that don't change?

Constants

Drag the correct HTML tag on the left to its description on the right.

Contains the title of the web page, links to stylesheets, and metadata to help search engines find the page. <head> Lets the browser know that it should interpret the document as HTML. correct answer: <html> Contains all the elements that will be presented on the screen. correct answer: <body>

Programming Fundamentals

Data type An attribute attached to a value that tells the compiler or interpreter how the data should be used. Identifier A user-defined name of a program element, such as a variable or constant. Container A program element, such as an array or vector, that holds a set of values. Function A computer routine or snippet of code that can be reused in a computer program. Flowchart A visual representation of the logic in a program. Branching The logic in a program that tells the computer to execute a specific part of the program rather than executing statements one-by-one, in order. Looping The logic in a program that tells the computer to repeatedly execute a sequence of instructions until a condition is reached. Algorithm Specific, step-by-step procedures that illustrate how a problem will be solved.

On a flowchart, which of the following represents a decision?

Diamond

What does the following JavaScript code snippet do when the code is loaded in a browser?

Displays the text "My JavaScript Button" and a button labeled "Click me!"

A developer is creating an application that requires a value to be stored with decimal precision. Which of the following data types should be used for the variables that will store these values?

Float

Using HTML and CSS to provide visual elements to the end user would be considered part of a website's _____________.

Frontend

Web Development

Frontend Development Programming development that creates the things users see and interact with on a website. Backend Development Programming development that handles the behind-the-scenes work of a website that's not apparent to the average user. This includes serving content to users, managing user accounts, and accessing information from databases. Hypertext Markup Language (HTML) A markup language interpreted by web browsers. Cascading Style Sheet (CSS) A file associated with a web page that describes how HTML elements are to be displayed. JavaScript A programming language commonly used to create interactive effects within a web browser.

HTML, CSS, and JavaScript

HTML HTML isn't a programming language, but a markup language. It is used to create the content and structure of a website. It specifies what should be displayed. It works by adding tags to text. The web browser interprets the tags to display the content we see on a webpage.Most tags have two parts, the opening tag that is surrounded by angle brackets (e.g., <html>), and the closing tag that has angle brackets and a forward slash (e.g., </html>).For example, in an HTML document, if we typed "<strong> "Hello World!"</strong>" and loaded it into a web browser, the browser would display Hello World! in bold letters. Common tags include the following: The <html> tag lets the browser know that it should interpret the document as HTML. The <head> tag contains the title of the webpage, links to stylesheets, and metadata to help search engines find the page. The <body> tag contains all the elements that will be presented on the screen. The <p> tag formats text as a paragraph. The <a> tag creates a hyperlink. The <h1> tag designates text as a first-level heading. CSS While you can use HTML to specify the style of text and images, it's cumbersome and inefficient. CSS gives websites their style (their look and feel). HTML specifies what should appear and CSS determines what it looks like. On most webpages, the table style, font, margins, and background are all generated by CSS. JavaScript JavaScript makes webpages interactive. JavaScript code tells the browser how to react to user inputs such as dragging the mouse. JavaScript tells the content from HTML and CSS what to do. As an example, consider the to-do list application below. It has an HTML file to give it structure and a CSS file to give it a style. However, without JavaScript the app is static; it doesn't do anything. If we click buttons or try to add a new item to the list, nothing happens. Adding JavaScript makes the webpage respond to input from the user such as deleting a task when you click the trash can, allowing users to add new items, and showing the input field when the user clicks the plus icon.

HTML Tags

HTML is a markup language. It works by taking a regular text document and using tags to designate parts of the text for different purposes. Generally, but not always, HTML tags have two parts—an opening tag (<tag>) and a closing tag (</tag>). This lesson is an overview of some of the most common HTML tags. <html> Most web pages, including the one you're looking at right now, are completely enclosed in <html> tags. This tag tells the browser that everything inside should be interpreted as HTML. <head> The <head> tag stores a web page's metadata, or information about the page. Metadata can include a title, subject, and keywords that relate to the page. The head can also hold links to other documents, such as stylesheets. <body> The <body> tag usually comes after the <head> tag. It contains the actual content of the web page. All the text, images, and links you see are part of the website's body. <div> The <div> tag is used to divide a website into different parts for different purposes. For example, one <div> may be used for a navigation bar, another for a side panel, and another for the site's main content. Using <div> tags this way makes it easier to organize and style each individual part of the page. <p> The <p> tag, or paragraph tag, is used to divide text into paragraphs. <p>Paragraph 1</p> <p>Paragraph 2</p> Paragraph 1 Paragraph 2 <h1> through <h6> These tags are used to create headings and subheadings in a document. <h1>Heading 1</h1> <h2>Heading 2</h2> <h3>Heading 3</h3> <h4>Heading 4</h4> <h5>Heading 5</h5> <h6>Heading 6</h6> Heading 1 Heading 2 Heading 3 Heading 4 Heading 5 Heading 6 <b> The <b> tag, or bold tag, makes any text inside it bold. <b>Hello, world!</b> Hello, world! <i> The <i> tag, or italics tag, italicizes any text inside it. <i>Hello, world!</i> Hello, world! <ul>, <ol>, and <li> <ul> and <ol> are used to create unordered (bulleted) and ordered (numbered) lists. Each list item is designated by <li> tags. <ul> <li>Bullet 1</li> <li>Bullet 2</li> <li>Bullet 3</li> </ul> -Bullet 1 -Bullet 2 -Bullet 3 <ol> <li>Item 1</li> <li>Item 2</li ><li>Item 3</li> </ol> 1-Item 1 2-Item 2 3-Item 3 <a> The <a> tag, or attribute tag, is generally used to create hyperlinks. This tag uses the href attribute to tell the computer where the link should go when it's clicked. <a href="https://www.testout.com">Link to the TestOut homepage</a> <img> The <img> tag, or image tag, is used to add an image to a webpage. Unlike the other tags listed here, <img> doesn't require a closing tag. However, it does need to use the src attribute to tell the browser where the image is located. <img src="https://www.testout.com/ images/Home/testoutlogo.png">

Which of the following BEST describes a back-end developer?

He or she accesses information from databases and prevents unauthorized access.

Which of the following BEST describes a front-end developer?

He or she is concerned with the aesthetics of a website.

Integrated Development Environments

IDE stands for integrated development environment, which is a set of programming tools that work together to make a programmer's job easier. Some programmers work in simple text editors, but these don't include the same kind of robust tools that an IDE can provide. Many IDEs are tied directly to a particular programming language, such as Ruby or Java. This helps them to be as useful as possible to the programmer working in that specific language. Using an IDE A simple text editor usually does only one thing—it edits text. This allows you to use any programming language that you know. However, these kinds of editors don't offer support for different kinds of programming styles and languages like IDEs do. An IDE allows for faster coding with less effort and for different programmers to easily collaborate on the same project. When considering an IDE, you should remember that there's going to be a learning curve associated with it. Because most IDEs are tailored to a specific programming language, no two will be precisely the same. This requires more effort to get up to speed on a new one. It's important to remember that an IDE can make it easier to spot mistakes, but it can't fix all your errors for you. You still need to be able to spot them yourself as no software is foolproof. Most IDEs include the following components: Text or code editor Project windows for convenience Compiler Debugger Language-specific features Once you've learned how to use an IDE, it can greatly streamline your work. The following are some of the added features that many IDEs provide to programmers: Autocomplete key words Highlights syntax, making it easier to follow Supports external plug-ins Displays your execution results in a separate window Can organize your work into folders that keep your project orderly

Which of the following can be used by a programmer to debug code?

Integrated development environment (IDE)

Alan, a programmer, needs to create an interactive web page. Which of the following programming languages types would he MOST likely use?

Interpreted

Python is a general purpose programming language that is popular for creating websites and mobile applications. Python is known as a readable and user-friendly language. What does the following code do? color = input('What is your favorite color?\n')print('Your favorite color is %s.' % color)

It gets input and produces output.

Which of the following BEST describes a flowchart?

It is a visual representation of the logic in a program.

Which of the following describes the declarative programming paradigm?

It uses a domain-specific language (DSL) to instruct the program what needs to be done.

A programming paradigm is a method used to program a computer that guides the solving of a problem or performing of a task. Which of the following describes the procedural, or imperative, programming paradigm?

It uses a linear, top-down approach to solving problems.

A software developer is working on a website and has been tasked with adding interactive elements to it. Which of the following programming languages would work BEST for this task?

JavaScript

Diana, a developer, needs to program a logic component that will allow the user to enter a series of values. Which of the following would BEST provide that functionality?

Looping

What does JavaScript do?

Makes web pages interactive.

Match each language to its general purpose in a website.

Makes website elements interactive JavaScript correct answer: Adds colors, fonts, and other design elements to website CSS correct answer: Creates website structure and content HTML

Which of the following job tasks would be something a QA specialist would do?

Monitor software development in order to maintain a high-quality product.

Which of the following programming models are built from class templates that have properties, attributes, and methods?

Objects

Basic JavaScript

Open an Online JavaScript Editor Open one of the following online JavaScript editors in your browser. W3Schools jsfiddle.net codepen.io Tutorials Point Enter and Run Sample Code Delete any contents in the left pane of the JavaScript editor. Enter the following code into the left pane Modify the Page Style Enter the following code above the first line (<body>) that you have previously entered <style> body { background-color: beige; text-align: center; color: chocolate; font-family: Arial; } </style> Click the "Run Code" or "Preview" button at the top of the left pane and see what changes in the right pane. Experiment with changing the colors, alignment, and fonts. What limitations do you find as you try different style options? Customize the Button Enter the following code just before the line that contains </style> button { text-align: right; height: 60px; width: 200px; background-color: GoldenRod; border-radius: 10px; border-width: 3px; border-color: SaddleBrown; } button:hover { background-color: DeepPink; cursor: pointer; } What changes do you see? Try changing the different options to customize your button.

Basic Python Scripting

Open an Online Python Compiler Open one of the following online Python compilers in your browser. Repl.it GDB Online Enter Code to Create Random Password Generator Delete any contents in the console pane of the Python compiler. Enter the following code into the console pane. import random characters = "abcdefABCDEF1234!@#$" length = 8 password = "".join(random.sample(characters, length)) print(password) Click the "Run" or "Execute" button above the console pane. Notice how a different password is generated each time you execute the code. Try changing the number of characters in the password as well as which letter, number, and symbols are utilized to generate the password. Enter Code to Simulate Dice Roll Clear the previous code from the Python compiler and input the following. Be sure to use consistent indentation. import random print("Roll the dice!") while True: input("Press Enter to roll") roll1 = random.randint(1, 6) roll2 = random.randint(1, 6) print(roll1) print(roll2) Click the "Run" or "Execute" button above the console pane. Notice how two different numbers are displayed each time you press Enter. Press the stop button above the console pane to end the program. To make sure you understand how this script works, add 2 more dice to the game and try it out. Create Your Own Python Script Write a script that can randomly select a classmate for a prize. Utilize the random function and the random.randomint() function you used in the dice game to select a random number out of 30 students.

Programming Logic

Programmers use logic to instruct a computer on how and when to perform certain tasks. Flowcharts The main purpose of flowcharts is to visually represent the flow (sequence) of logic in a program. An advantage of using flowcharts is that they make programming logic easier to read, especially for those who have little experience with programming. Flowcharts allow you to visually follow the sequence of steps the program takes. The following are important symbols associated with flowcharts: ⊂⊃ Pill Shape - Pill shapes represent the start or end of a program. ▱ Parallelogram - Parallelograms represent input or output. ◇ Diamond - Diamonds represent decisions answered with a Yes or a No. ▭ Rectangle - Rectangles represent processes. ➝ Arrow - Arrows determine the logical flow of the program. Branching By default, computer programs start at the first line, then execute one line at a time until the end. However, many programs need to change their behavior based on user input or other circumstances. This is called branching. Consider the following common example. In the pseudocode (the plain language description of what the code is doing), the program is watching for the user to click Add to cart. When they do, it checks to see whether the user is logged in. If the user is, the code adds the item to the cart and suggests similar items. If not, the user gets redirected to the login page. This type of conditional branching is typically made up of IF-ELSE statements inside the program. In the example, if the user is logged in, the program runs the code under the IF statement. Otherwise, it runs the code under the ELSE statement. Looping One thing computers excel at is doing the same thing over and over in exactly the same way. In programming, this is called a loop. There are two main types of loops: for loops and while loops. For loops run a specific number of times. Using the online store example: The user adds a few more items to the shopping cart and is ready to check out. On the checkout page, the computer loops through the items in the cart, running the for loop for each item. It displays the item name to the list and adds the price to the running total. The number of times the loop runs is determined by the number of items. After the last item, the loop stops. While loops keep running as long as a certain condition is met. Consider the following example from an online card game. The game has a block of code that says while cardsInHand < 5. When the program gets to this block, it checks the number of cards in the player's hand. If it's less than 5, it removes a card from the deck and puts that card into the player's hand. Then, it loops back to the top and checks again. If the number of cards in hand is still less than five, it deals another card. Once the player has five cards, this condition is no longer met, so the loop stops running. Algorithms Algorithms are specific, step-by-step procedures that illustrate how a problem will be solved. They include all the necessary logic, such as conditional statements, branches, and loops. Before they are implemented in code, algorithms are often expressed in flowcharts or in pseudocode. Operators Just as there are operators in a math sentence that specify what to do with the numbers, there are operators in code. Each coding language has its own operators. For pseudocode, there are some basics to be familiar with. Relational operators: == is equal to. This means it returns TRUE if both conditions are the same. = is equal to. != is not equal to. > greater than. < less than. >= greater than or equal to. <= less than or equal to. Logical operators (used to test multiple conditions simultaneously): AND - If both statements are TRUE, the whole statement is considered TRUE. OR - If either condition is TRUE, the whole statement is also considered TRUE. XOR - If only one of the conditions is TRUE, the whole statement is considered TRUE. NOT - The whole statement is not TRUE. Pseudocode of other programming languages: && - If both statements are TRUE, the whole statement is considered TRUE. || - If either condition is TRUE, the whole statement is also considered TRUE. ! - The whole statement is considered not TRUE. Other keywords: START - Starts the pseudocode. INPUT - Data provided through a keyboard or other input device. GET/READ - Input taken from a data file. PRINT/SHOW/DISPLAY - Displays output on the screen. SET/INIT - Initializes values. Comments As you write your code, it is very helpful to document what the sections of the code do. This way when you or a coworker come back to update or troubleshoot the program, you can easily see what was intended. When adding comments, keep in mind: To add documentation within the program itself, you must use a comment symbol or delimiter. This symbol may vary, depending on the program being used, but common comment symbols include the hash (#), an apostrophe ('), or double forward slashes (//). Lines of code that are preceded by a comment symbol are ignored by the program when the code is run. Procedures and Functions The purpose of pseudocode is to explain in a concise and easily understandable way what the code will do. It should be easy for another programmer to understand and follow. Be sure to eliminate any extra or confusing statements.Often you can use the same segment of pseudocode multiple times. Programmers learn quickly that it is a time-saver to reuse code. The code that you reuse repeatedly is called a procedure or a function. Procedure - A specific piece of code that can be reused without creating any output and without needing input. Function - A specific piece of code that can be reused, but requires input and output.

Programming Paradigms and Processes

Programming Paradigm A method a computer uses to solve a specific problem or perform a specific task. Procedural Programming A method that focuses on telling a computer what to do to reach a certain objective. It takes a linear, top-down approach to solving problems by creating routines and subroutines that perform computations. Declarative Programming A method that focuses on instructing a program what needs to be done instead of telling how to do it. Instead of giving the computer step-by-step instructions, the code simply says what the end result must be. Object-Oriented Programming (OOP) A programming paradigm based on the concept of objects which can contain both data and programming code. Encapsulation An OOP concept that describes how data and methods are bundled together within one unit or class. Version Control Systems (VCS) Software tools that help teams manage files and source code over time. Integrated Development Environments(IDE) A set of programming tools that work together to make a programmer's job easier. Application Programming Interfaces (API) A set of protocols and tools that help programmers build applications that connect or communicate with databases, operating systems, and other services.

Working with Pseudocode

Pseudocode is a way to represent code in a way that's easy for a wide range of people to understand. It isn't valid code; it's more like a simplified explanation of what's going on without too much jargon. With pseudocode, you can walk someone through a process or walk them through the entire program. You show them where it starts and ends and what you expect the results to be from all the inputs and outputs. You would cover any branching events in the code that could possibly be relevant. Algorithm A Consider the following example of pseudocode. What do you think this program is meant to do? If student's grade is greater than or equal to 65 Then print "You passed. Good job!" Else Print "You failed. Try again!" This pseudocode shows a typical if/else statement in which the program chooses between two conditions based on input. If the first condition (the student gets a grade of 65 or higher) is met, there's one outcome: the message "You passed. Good job!" is printed. If the first condition is not met, there's another outcome: the message "You failed. Try again!" is printed. Algorithm B Consider the following example of pseudocode. What do you think this program is meant to do? INPUT drink CASE drink of water: PRINT "water" juice: PRINT "juice" soda: PRINT "soda" OTHERS PRINT "Please enter a valid order." ENDCASE n this example, the user is meant to select one of three options. The program will ask for input and then print the result based on what the user chooses. If the user does not make a valid selection, it prompts to make another choice. The branching decision tree is set off by the words CASE and ENDCASE. Algorithm C Consider the following example of pseudocode. What do you think this program is meant to do? FOR every class in the school Compute number of students ENDFOR This pseudocode is representing what's known as an iteration. The FOR statement creates a computational loop that's carried out for each specific set of elements (the classes in the school), one after the other. The code isn't meant to stop until each class has been run through the loop and the number of students in each class has been tallied. After all relevant iterations are complete, the loop ends.

Which of the following flow chart concepts is depicted below?

Sequence

History of Programming Languages

The history of computer programming goes back further than you probably realize. After Charles Babbage designed his Analytical Engine in the mid-1800s, he met Ada Lovelace, who is considered by historians to be the first computer programmer. She wrote an algorithm to calculate Bernoulli numbers using the Analytical Engine. Since that time, computer programming has evolved to match the capabilities of the complex supercomputers of the modern era that can perform mind-boggling numbers of calculations in a single second. But the basic purpose of programming remains the same—to give specific instructions to a computer. The First Major Languages In 1949, a low-level language called Assembly Language was created to run the Electronic Delay Storage Automatic Calculators (EDSAC). The first compiled programming language appeared in 1952 and was called Autocode. The code could be translated into machine code that a computer could use by running it through a program known as a compiler. Most of the first major languages used to program computers are no longer in use today, but they provided the building blocks on which more modern languages were built. The Second Major Languages The second major leap occurred soon after and involved languages that are still in use by programmers today, some of which were developed as far back as the 1950s. These include languages such as FORTRAN (Formula Translation), LISP (LISt Processor), and COBOL (Common Business Oriented Language). FORTRAN In 1957, American programmer John Backus created FORTRAN to take care of complex math problems. It's one of the oldest languages still in use today. BASIC In 1964, the programming language BASIC was modified by Paul Allen and Bill Gates and became the first product made by their company, Microsoft. Pascal In the 1970s, a high-level language was developed for teaching structured programming and was called Pascal after the French mathematician and physicist Blaise Pascal. C In 1972, a general-purpose, low-level language called C was created. C was based on an earlier language called B and came to be used extensively in Unix operating systems. Almost all programming languages in meaningful use today are based on C, such as C#, Java, JavaScript, Perl, PHP, and Python, among many others. It was the choice of the earliest programmers who worked on Apple Computers as well. C++ In 1983, an extension of C was created called C++. This was an intermediate-level, object-oriented language that contained more features than C, like templates and virtual functions. Perl In 1987, American programmer Larry Wall created Perl. Perl is a high-level, general-purpose language that was made to run on Unix systems. It's still in use today, though at this time Perl is considered to be slowly fading into the status of a legacy language. In the late 1990s, however, Perl was said to be the glue that holds the internet together. Python In 1991, a Dutch programmer named Guido van Rossum created a language that he called Python, which was named after the Monty Python comedy troupe. It was a general-purpose language and was made to support a variety of programming styles while still being easy to use. Python is still very much in use today. Many large companies, such as Google and Yahoo, use Python extensively, and for the foreseeable future it will be the premier language for developing Artificial Intelligence (AI). Ruby In 1993, Japanese programmer Yukihiro Matsumoto created Ruby, which is a general-purpose, high-level language that was meant to teach others how to code. It was influenced by other languages such as Perl. It's still used by major websites such as Twitter and Groupon. Java In 1995, Canadian programmer James Gosling created Java while working for Sun Microsystems. Java is a general-purpose, high-level language that was originally developed for an interactive TV project and was designed to have cross-platform functionality. Java is among the most widely used programming languages in the world today and used extensively by Android apps. PHP In 1995, Danish-Canadian Rasmus Lerdorf create PHP, which stood for "Personal Home Page." It was an open-source, general purpose language for creating dynamic web pages mainly on the server side. PHP is used in all corners of the internet, including by Facebook, Wikipedia, and WordPress. By some estimates, almost 80% of all websites still use PHP in some capacity. JavaScript In 1995, American programmer Brendan Eich created JavaScript, which is a high-level language that was made to extend the interactivity of websites. It's almost exclusively the language of use on the front end (client side) of websites. In other words, because of JavaScript we have the ability to easily click a button, fill out a form, check out a link, and much more.

To be a proper HTML document, there are a few tags that every web page needs. Put these tags in the proper order.

The proper order is: <html> <head> </head> <body> </body> </html>

Application Programming Interfaces

The term API stands for application programming interface. Programmers use APIs to connect or communicate with databases, operating systems, and other services. APIs define both protocols and tools for programmers to build applications. A web APIs is a specific type of API that governs the access points of a web server that receives requests and sends responses. An API is a bit like a restaurant menu. It includes a list of operations a system or site can perform and a description of each. When someone makes a request for one, the API delivers it to that user. A user doesn't need to know how a specific operation works; they only need to know what it's supposed to do. Developers save a lot of time by using APIs since they let the program take care of the nuts and bolts behind the scenes. With web APIs, it's important to remember that the API is not the server itself. It's basically a collection of code that helps the server accomplish useful tasks. The creation of an API usually doesn't require any knowledge of HTML or CSS because it's stored in XML format or as a JSON file, which stands for JavaScript Object Notation. One common API that's seen across a variety of websites is the OAuth API. This is an API that allows users to log into a website using a different account such as a Google, Twitter, or Facebook profile, even if he or she has never signed into the site before. This API can automatically create a new account for you based on your existing one. The next time you visit the site, you can easily log in again with the same account you previously used. You can also use an API to share content like blog posts on various social media. Who Uses APIs? Software developers use APIs to make their jobs easier. If you want to build an app for a particular operating system, such as Windows or macOS, that operating system will already have a large number of APIs that you can draw from in order to make things easier. For example, let's say you're building an app and want it to be able to take a photo using the phone's camera. That isn't something you need to code from scratch. The operating system should already have an API for this function which you can insert into your app and save yourself a great deal of time and effort. APIs are also helpful because they always stay up to date. When your website uses an embedded Google Maps widget, it always returns the most up-to-date version. You don't have to constantly update the content yourself and the user experience is always consistent.

Programming Paradigms

The word "paradigm" in Information Technology means a method used to solve a problem or perform a task. A programming paradigm is a method a computer uses to solve a specific problem or perform a specific task. Each paradigm has its own set of tools at the programmer's disposal, and they are generally used for different purposes, though they often complement each other. Procedural Programming The procedural programming paradigm focuses on telling a computer what to do to reach a certain objective. It takes a linear, top-down approach to solving problems by creating routines and subroutines that perform computations. It's sometimes also known as imperative programming. The programmer splits his or her code into smaller units, called functions or procedures, so that they can be reused when the need arises. When the program is compiled, it's executed in a linear order, going to the first function, and then the second, and so on until the last function is executed. This kind of programming easy to write and understand, and it's often the first paradigm taught in introductory programming classes. Declarative Programming Declarative programming focuses on instructing a program what needs to be done instead of telling it how to do it. Instead of giving the computer step-by-step instructions, the code simply says what the end result must be. Examples of the declarative paradigm are markup languages like HTML, style sheet languages like CSS, and query languages like SQL.

A software developer wants to create an application that will work on Windows and Apple iOS operating systems. What can the developer do to make this task easier?

Use the APIs for each operating system.

A developer is creating a program that will store a customer's latest order number. The value will change each time a customer creates a new order. Which of the following would MOST likely be used to store the value?

Variable

What is the term for code that keeps running as long as a certain condition is met?

While loop

Python provides programming functions that can be used by a software developer. Which of the following would be used to make the random function available?

import random


Kaugnay na mga set ng pag-aaral

Warrantless Searches and Seizures

View Set

ITIL Service Design Availability Management

View Set

CIE A Level: Control and Coordination

View Set

Ch. 13 Project Planning and Scheduling

View Set

PrepU: Chapter 19-Lung Assessment

View Set

unit 4: frankenstein + romanticism

View Set