Categories
News

How to Copy Formulas in Microsoft Excel | MakeUseOf

One of the great things about working digitally is that it can cut down on a lot of unnecessarily repetitive work. For example, if you must fill the same content into multiple cells in a spreadsheet, you can just copy and paste the values to save time.

Although, this can get a little tricky if you need to copy formulas. Luckily, Excel has several ways to copy and paste formulas. But, there are a couple of things you need to keep in mind when doing so.

Relative Cell References

Before we can jump into copying formulas, you need to know a little bit about how Excel references cells. Excel tracks the relation between the cells in the formula, not the actual cells.

For example, in the image below, cell C2 contains the formula A2 + B2. But thanks to relative cell references, Excel reads this as: add the cell that is two places to the left to the cell that is one place to the left.

These relative cell references can be very handy. If you want to add the values on row 3 and 4 in the same way you did for row 2, all you have to do is copy the formula down without worrying about changing the rows yourself. Excel updates the rows in each formula so that the cells to the left of that add together.

However, sometimes you don't want a cell's location to change when you copy a formula.

For example, let's say you want to work out the sales tax on a series of products, as we've done below. If you add the sales tax to one cell, you want that cell to remain the same in the formula for each product. To do this, you need to tell that Excel the location of that cell is fixed, not relational. You do this with a $ sign in front of the row, column, or both.

Adding the $ before the B tells Excel that no matter where we paste the formula, we want to look at the B column. To stop the row from changing, we also added a $ before the 1. Now, no matter where we paste the formula, it will always reference B1 for the tax value.

As we copy the formula down the column, the price location updates, but the sales tax location stays the same.

Using the F4 Keyboard Shortcut

There is a keyboard shortcut to toggle through a cell’s reference options. When you're writing a formula and click on a cell, hit F4 to fix that cell. For example, if you click on B1 and press F4, it changes the reference to $B$1. If you press F4 again, the cell reference changes to B$1, then to $B1, and finally back to B1.

Copying and Pasting a Formula Manually

The most familiar way to copy and paste a formula is to copy and paste the formula text inside a cell. This is similar to how you would copy and paste text in Word.

Copy the text by selecting the cell and right-clicking the formula at the top of the screen. This brings up a popup with various options, select Copy. You can also use the copy button in the ribbon, which is located in the Clipboard section of the Home tab.

Then unselect the text by pressing the Return key. Finally, right-click the new cell you want to paste into and click on the clipboard icon or use the Paste button in the ribbon. You can also use the keyboard shortcut, Ctrl + C, to copy the highlighted text and Ctrl + V to paste it once you select a new cell.

This method is familiar, but not one of the best ways to copy a formula. If you had to copy a formula to multiple cells it would be time-consuming. This method also copies your exact text, so you don't get the benefits of relative cell references we talked about above.

You should only use this method if you only need to copy the formula to a couple of places and you want the cells to remain exactly the same each time.

Related: Excel Quick Tips: How to Flip Cells & Switch Rows or Columns

A Better Way to Copy a Formula in Excel

An easier way to copy the formula is to use copy and paste on the entire cell instead of just the text inside it. Click on the cell with the formula you wish to copy. Then copy it by either right-clicking on the cell, or using the keyboard shortcut Ctrl + C.

Once you copy the cell, it will have a dashed green border to show that you are currently copying it. Next, select the cell you want to paste the formula to. Then paste the formula by either right-clicking on the cell, or using the keyboard shortcut Ctrl + V.

This time, you'll notice the formula uses relative cell references. Instead of A2 + B2, a formula on the row beneath becomes A3 + B3. Similarly, if you pasted the formula in the next column in the row beneath, it would update to B3 + C3.

How to Drag a Formula Down a Column or Across a Row

The method above can still be too time-consuming if you need to paste the same formula to multiple rows or columns. Luckily, there are two even quicker ways to do this.

First, you can copy the formula as you did above, but instead of pasting it to one cell, you can click and drag to select multiple cells and paste the formula to all of them by right-clicking any the cell or using the keyboard shortcut Ctrl + V.

The second way to paste the same formula to multiple rows is to drag it. At the bottom-right corner of a selected cell, you'll see a green square. Click on that square and drag it over the cells you wish to copy the formula to. This is probably the quickest way to copy an Excel formula down a column or across a row.

Again, you'll see that Excel updates the formula to use relative cell references for each row or column that changes.

Related: Excel Autofill Tricks to Build Your Spreadsheets Faster

Paste Special

One problem you may have when pasting a formula is that it also pastes any styling to the selected cells. Styling includes elements like the font size, cell outline, colors, or bold settings. Pasting the styling is inconvenient if you use alternate line colors or if you outlined your table.

To solve this, Excel introduced Paste Special.

Use Paste Special to paste just the formula without any of the styles that were added to the cell. To use Paste Special, right-click and select Paste Special from the popup menu.

A Recap of How to Copy and Paste Excel Formulas

Excel is optimized to reduce the number of repetitive tasks that you need to complete. Adding the same formula to multiple cells is quick and easy to do in Excel. You can copy and paste formula text, much like you would in a Word document. But if you want to take advantage of relative cell references, you're better off using different methods.

A good way to copy a formula is by selecting the entire cell with the formula and copying that. If you need to copy a formula down a column or across a row, you can also drag the cell across the area you want to copy it to, which is much quicker.

Both methods allow you to copy a formula to multiple cells quickly. Next time you create a spreadsheet, remember to try it out and save yourself some precious time.

Categories
News

How to Write a for Loop in Java | MakeUseOf

Loops are very powerful programming tools that will complete a set of instructions until a condition is met. They are very handy and should be one of the first programming concepts that you learn. There are many different types of loops, but for loops are arguably one of the most useful loops.

The For Loop in Java

For loops will continue to execute a block of code until a condition is met. It is important to note that a for loop will check the condition at the beginning of the loop, not the end. This means that if the condition is met, the loop will not start.

For loop syntax is similar across programming languages. So, if you have created a for loop in another programming language, a Java for loop will look familiar. However, if you are not familiar at all with Java, it is recommended that you read a beginner's tutorial before learning advanced topics like for loops.

for([statement1]; [condition]; [statement2]){
//code to execute each loop
}

The keyword for indicates a for loop. The condition that determines how long the loop will continue is located between the brackets. The first statement is run once when the for loop is initiated. The condition defines when the loop should stop. The second statement is executed at the end of every loop. Semicolons mark the end of statement1 and the condition. Typically, the statements are used to create a counter and the condition stops the loop once the counter reaches a specific number. Finally, the code that is executed in each loop is placed between the curly brackets.

public class Main{
public static void main(String[] args) {
for(int i = 1; i < 4; i++){
System.out.print(i);
}
}
}
//Output: 123

In the example above, the for loop prints out the value of i. The keyword for initializes the loop. The variable i is initially set to 1. The condition checks whether i is four or greater. This isn't the case, so our loop is executed. The loop code prints out the value of i, which is still 1 at this point. Once the loop code is completed, i is incremented by one and the loop begins again. At the end of the third loop, i is increased to four. When the next loop begins, our condition is met, so the loop stops.

Related: Core Java Concepts You Should Learn When Getting Started

Nested For Loop

Once you get the hang of a for loop, you should try to create a nested for loop. This is when you have a for loop inside of another for loop. This is an advanced technique because it can be difficult to understand how the two loops will interact. A good way to visualize how nested for loops work is to create the following pattern with a nested for loop.

*
**
***

To create this, we will need one loop to control how many stars are printed on each line, and another loop to control how many lines to create. When you are new to nested for loops it can be difficult to determine which loop is the inner loop. In this case, the loop that prints the stars is the inner loop. We need that loop to run each time a new line is created.

When creating a nested loop, be careful when you choose the name of your counter variables. Although often programmers use a generic i counter, using generic counters becomes confusing when multiple loops interact.

for(int lineCounter = 1; lineCounter < 4; lineCounter++){
for(int starCounter = 1; starCounter <= lineCounter; starCounter++){
System.out.print("*");
}
System.out.print("\n");
}

Let's run through this example to better understand how it works. Our first loop is counting how many lines we make. After the loop executes three times, it will stop. The next loop is a tad more complex. This loop controls how many stars are printed on each line. In our pattern, we want the same number of stars as the line number. The first line has one star, the second two, and the third three. So, we want that loop to print as many stars as our current line counter. After our star loop is completed, the line loop creates a new line by printing \n, which is the command for a new line.

Infinite Loops

One of the dangers of coding any type of loop is that you can accidentally create an infinite loop. These are loops that never stop. Although there are cases when an infinite loop is needed, generally, they are created by accident when the loop's condition is not carefully planned. In these cases, the program will continue to run until you force it to close.

To create an infinite loop, you can use the following syntax:

for(;;){
//code that never stops looping
}

Related: Websites & Apps That Can Help When Learning Java Programming

Using a For Loop with an Array

A common way to use a for loop is to iterate through an array. For example, if you want to print all of the strings in an array, you cannot simply say

System.out.print([array]);

This command would print information about the array, not the contents of the array. To print the contents of the array, you have to print each individual element in the array. This would be time-consuming to code, but you could create a for loop to go through each element.

String[] words = {"Hello", " ", "World", "!"};

for(int i = 0; i < words.length; i ++){
System.out.print(words[i]);
}

Remember, array positions start at zero, not one, so we want our loop to start at zero. Our first loop will print Hello, the second loop will print a space, and so on. After the fourth loop, our counter will be incremented to four, which is not less than the length of the array, which is also four. This will stop the loop.

Output:

Hello World!

For-Each Loop

Although you can use a for loop to iterate over an array, it is easier to use a for-each loop. These loops are designed specifically for arrays. A for each loop will go through each element in an array and execute code. For-each loops have a slightly different syntax. The keyword for is still used, but a condition is not specified.

for([dataType] [arrayElement] : [array]){
//code to be executed
}

Our previous example can be re-written as a for-each loop using this syntax:

String[] words = {"Hello", " ", "World", "!"};

for(String word : words){
System.out.print(word);
}

The loop is started with the keyword for. We then specify that the data in our array are strings. Next, we choose a variable name to refer to the elements in the array as we iterate through the loop. In this case, we used word. This is followed by a colon and the name of the array we want to iterate through. Now, inside our loop, we just have to use the variable word to refer to each element in the array.

When to Use a For Loop

For Loops are great tools that can save you a lot of coding. They are the best type of loop to use when you know exactly how many times you want your loop to run. You can even increase the complexity of for loops by nesting them. Nested for loops are particularly handy when working with multi-dimensional arrays. For loops are easy to learn and an important skill for beginners. This technique is sure to save you from coding unnecessary repetitive code.

Categories
News

How to Set a Background Image in CSS | MakeUseOf

Creating a website is a great way to express yourself. Although there are many website building tools, writing it yourself is a fun way to learn more about how websites work behind the scenes. A good beginner project is to create a website and add a background image with CSS. This project will get you up and running with both HTML and CSS.

What is CSS?

CSS stands for Cascading Style Sheet. It is a programming language that allows you to style markup languages. One such markup language is HTML or Hyper-Text Markup Language. HTML is used to create websites. Although you can control some of the website's style using HTML, CSS offers much more control and design options.

Creating a Basic Website With HTML

Since CSS is just a style language, to use it, we first need something to style. A very basic website will be enough for us to begin playing with CSS. Our page will display "Hello World."

<html>
<head>
</head>
<body>
<p>Hello World</p>
</body>
</html>

In case you are not familiar with HTML, let's quickly go over what all of the elements do. As mentioned, HTML is a markup language, which means that it uses tags to mark what the text is. Whenever you see a word surrounded by <> it is a tag. There are two types of tags, a tag that marks the beginning of a section using <> and one that marks the end of a section using </>. The text within a section is also intended to make this distinction easier to see.

In our example, we have four tags. The html tag indicates which elements are part of the website. The head tag contains the header information that is not displayed on the page but is needed to create the page. All of the displayed elements are between the body tags. We only have one displayed element, the p tag. It tells the web browser that the text is a paragraph.

Related: 10 Simple CSS Code Examples You Can Learn in 10 Minutes

Adding CSS to HTML

Now that we have a simple page, we can customize the style with CSS. Our page is pretty simple right now, and there is not much we can do, but let's begin by making our paragraph stand out so we can distinguish it from the background by adding a border.

<html>
<head>
</head>
<body>
<p style="border-style: solid;" >Hello World</p>
</body>
</html>

Now, our paragraph will be surrounded by a black border. Adding a style description in CSS to our paragraph tag told the website how to style the paragraph. We can add more descriptions. Let's increase the white-space, or padding, around our paragraph and center our text.

<html>
<head>
</head>
<body>
<p style="border-style: solid; padding: 30px; text-align: center" >Hello World</p>
</body>
</html>

Our website looks better, but our HTML is starting to look messy with all of those descriptions in the paragraph tag. We can move this information to our header. Our header is for information that we need to display the website correctly.

<html>
<head>
<style>
p {
text-align: center
}
#ourParagraph {
border-style: solid;
padding: 30px;
}
</style>
</head>
<body>
<p id="ourParagraph" >Hello World</p>
</body>
</html>

Now our HTML is easier to read. You will notice that we did have to change some things around. The style tag tells the web browser style information, but also what to style too. In our example, we have used two different ways to tell it what to style. The p in the style tag is telling the web browser to apply that style to all paragraph tags. The #ourParagraph section tells it to only style elements with the id ourParagraph. Notice that id information was added to the p tag in our body.

Importing a CSS File to Your Website

Adding the style information to the header makes our code much easier to read. However, if we want to style many different pages the same way, we have to add that text to the top of every page. That might not seem like much work, you can copy and past it after all, but it creates a lot of work if you want to change an element later.

Instead, we are going to keep the CSS information in a separate file and import the file to style the page. Copy and paste the information between the style tags into a new CSS file ourCSSfile.css.

p {
text-align: center
}
#ourParagraph {
border-style: solid;
padding: 30px;
}

Then, import the file to the HTML file.

<html>
<head>
<link rel="stylesheet" href="ourCSSfile.css">
</head>
<body>
<p id="ourParagraph" >Hello World</p>
</body>
</html>

Adding a Background Image With CSS

Now that you have a solid base in HTML and CSS, adding a background image will be a piece of cake. First, identify what element you want to give a background image to. In our example, we will add a background to the entire page. This means that we want to change the style of the body. Remember, the body tags contain all the visible elements.

body{
background-image: url("sky.jpg");
}
p {
text-align: center
}
#ourParagraph {
border-style: solid;
padding: 30px;
}

To change the body style in CSS, first use the body keyword. Then add curly brackets as we did before {}. All of the style information for the body must be between the curly brackets. The style attribute we want to change is background-image. There are many style attributes. Don't expect to memorize them all. Bookmark a CSS properties cheat-sheet with attributes that you want to remember.

Related: 8 Cool HTML Effects That Anyone Can Add to Their Website

After the attribute, use a colon to indicate how you will change the attribute. To import an image, use url(). it indicates that you are using a link to point to the image. Place the file location in the brackets between quotation marks. Finally, end the line with a semicolon. Although white space does not have meaning in CSS, use indentation to make the CSS easier to read.

Our example looks like this:

If your image is not displaying correctly because of the size of the image, you can alter the image directly. However, there are background style attributes in CSS that you can use to alter the background. Images that are smaller than the background will automatically be repeated in the background. To turn that off, add background-repeat: no-repeat; to your element.

There is also two ways to make an image cover the entire background. First, you can set the background-size to the size of the screen with background-size: 100% 100%;, but this will stretch the image and may distort the image too much. If you do not want the proportions of the image changed, you can also set the background-size to cover. Cover will make the background image cover the background, but not distort the image.

Changing the Background Color

Let's change one last thing. Now that we have a background, our paragraph is hard to read. Let's make it's background white. The process is similar. The element we want to modify is #ourParagraph. The # indicates that "ourParagraph" is an id name. Next, we want to set the background-color attribute to white.

body{
background-image: url("sky.jpg");
}
p {
text-align: center
}
#ourParagraph {
background-color: white;
border-style: solid;
padding: 30px;
}

Much better.

Continuing to Design Your Website With CSS

Now that you know how to change the style of different HTML elements, the sky is the limit! The basic method to change style attributes is the same. Identify the element that you want to change, and describe how to change the attribute. The best way to learn more is to play around with different attributes. Challenge yourself to change the color of your text next.

Categories
News

How to Calculate Weighted Average in Excel | MakeUseOf

Excel is a very handy tool to track progress and calculate averages. But data isn't always straightforward and sometimes the mean average doesn't do the job. What do you do if not all of the values are equally important?

That's where you need a weighted average.

A weighted average can give your data more meaning, and it's easy to calculate the weighted average using Excel. Here's what you need to know.

What Is a Weighted Average?

You're probably already familiar with averages. When you calculate a mean average in Excel, you add up a set of values and then divide the total by the number of values in the set. This is great when all the values equally contribute to the average. But it's not suitable when you want some values to have more impact on the resulting average.

The most likely place you will have seen weighted averages in the wild are grade calculations in school. In most courses, assignments and tests contribute differently to your overall grade. A final exam or midterm generally has a greater impact on your grade than a quiz.

Weighted averages allow you to specify how much you want something to contribute to an average. Each value is assigned a weight. The weight determines how much that value will contribute to the average. Our example will look at grades in a course.

How Do You Calculate a Weighted Average?

Weighted averages are calculated similarly to mean averages, but there are two key differences. First, you multiply the values in your number set by their weight before adding them together. Second, instead of dividing the total by the number of values in the set, you divide the total by the sum of the weights.

In our example, we would multiple the grades by their weights and add them together:

(5 * 78) + (5 * 82) + (10 * 77) + (20 * 87) + (20 * 81) + ( 40 * 75) = 7930

Then, we would add up the weights:

5 + 5 + 10 + 20 + 20 + 40 = 100

Now, we simply divide the total weighted values by the total weights:

7930 / 100 = 79.3

So, the weighted average in this example is 79.3 percent. Knowing how to calculate the weight value by hand is useful, but time-consuming. It's far easier, and quicker, to calculate weighted averages in Excel instead.

How to Calculate a Weighted Average in Excel

Weighted averages can be calculated in the same way in Excel, as we've done below:

Column D contains the weight multiplied by the grades. Cell D2 has the command =C2*B2, D3 has =C3*B3, and so forth.

The total of the products of weight and grades is in cell D8. We calculated the total using the sum function =SUM(D2:D7), which sums all the values between D2 and D7. Similarly, the total of the weights is in cell B8, also using the SUM function.

Finally, the weighted average is calculated by dividing cell D8 by cell B8.

Related: 14 Tips to Save Time in Microsoft Excel

If this still seems like too much work, you're right! Excel offers many functions that simplify common calculations. In this case, we can use SUMPRODUCT to decrease the amount of work.

Using the SUMPRODUCT Shortcut

SUMPRODUCT does pretty much exactly what it sounds like, it returns the sum of the products of multiple data sets.

In our example, the cell B9 contains the formula: =SUMPRODUCT(B2:B7, C2:C7). SUMPRODUCT is the function call, and it requires sets of numbers to multiply and then add together.

In our example, we've given the function two data sets, the values from B2 to B7 and the values from C2 to C7. You can use as many data sets as you like, as long as each data set has the same number of values.

If you prefer to enter your functions using the Function Arguments window, you need to enter your data sets into the array blanks. Click on a box, then highlight the data you wish to enter. Don't worry if you have more than three data sets, as you add a data set, a new array box will appear.

SUMPRODUCT will multiply all of the first values in the data set, and add that to the product of all of the second values and so forth. Using SUMPRODUCT saves the step of multiplying each row in the columns and summing them as we did in the first example.

From here, you only need to add up the weights and divide the SUMPRODUCT by the result. To calculate the total weights, we used the SUM in the previous example.

Finally, we divided cell B9 by cell B10 to calculate the weighted average.

When to Use a Weighted Average

The most likely place you have seen weighted averages is in school. But aside from calculating your course average, you can also use a weighted average to calculate your grade point average across multiple courses worth different credits.

Most courses will have credit values of between 1 to 5 credits and your overall grade will be weighted by the number of credits each course is worth.

The next most common place you're likely to run into weighted averages is with sports statistics. Consider comparing the batting averages of two baseball players. The first player gets many hits, but barely any home runs. The second player gets more home runs but also has more no-hits. Which player is better?

Weighted averages give a fair way to compare the two players. In our simplified batting statistics example, we found that Player 2 was the better player, despite the fact that they got many no-hits. This is because the home runs are more valuable to the team.

An important difference in this example is that we divided our SUMPRODUCT by the number of times at bat instead of the total weight. This is because we're not interested in the average over types of hits, but the average over times at bat.

Weighted averages are powerful because they allow you to compare apples to oranges. As long as you can quantify the relative values of different features, you can create a weighted average to compare different datasets.

Exploring Weighted Averages

Now that you know how to create a weighted average, you can get started analyzing your data with more accuracy. As we mentioned, calculating weighted averages in Excel is particularly valuable for teachers and students, but they have far more uses than that.

Next time you have to compare values with different levels of importance, try making a weighted average chart in Excel. It's a great way to use Excel for solving real-life problems.

Categories
News

What Is the Difference Between UI and UX Design? | MakeUseOf

It is common to see job postings for UI Designers, UX Designers, and even UI/UX Designers. But what exactly is the difference between UI and UX? UI stands for user interface, and UX stands for user experience. This can be confusing because often, people think that the user's interaction with the interface is synonymous with the user's experience. But there are key differences that distinguish UI from UX.

UI designers and UX designers usually work closely together, but they are focusing on different things. Both UI and UX designers are interested in the design of the application, just different aspects. To better understand this, let's look at each role.

What Is User Interface Design?

User interface refers to the graphical aspects of design. This includes all the design aspects that the user can see and interact with.

The focus of UI design is to make an interface that is functional and allows the user to complete the tasks they need while being visually appealing. The UI designer might also be the front-end developer and code the front-end code. However, the UI designer could also create templates and designs, which a front-end developer then programs.

What Is User Experience Design?

User experience focuses on whether a product met the needs of its users. UX designers want to know how people are using a product and if the design helps them to accomplish their goals. Their job is to optimize a product beyond ensuring that it is functional.

The bulk of a UX Designer's job is to complete usability tests to understand if users can complete tasks that matter to them and if they want to use the product. They do not necessarily design or code the interface, but they do refine the design to better suit the end-users' needs.

UX design can encompass aspects beyond the design of the product as well. A UX designer has to consider how their user-base will discover the product and understand how the user's experience will shape their feeling about the company as a whole.

Related: Want to Be a UX Designer? Here's How to Get Started

How Does UI and UX Differ?

Simply put, UI cares about how something is designed, and UX cares more about how it is used. To better illustrate this, let's consider how a UI and UX designer would approach assessing software.

Gimp is a popular GNU Image Manipulation Program. It is a good program, but, like most open-source software, there is always room for improvement.

This is an image of the interface:

The UI designer would work on making everything you can see and interact with here aesthetically pleasing and functional. A UI principle that Gimp implements well is its use of uniformity. If you right-click on the canvas, the menu options along the top are displayed. They are shown in the same order and have all of the same options available.

Gimp's graphical interface has been streamlined over time to have a minimalist design. Previous versions had colored icons and multiple windows. The new design is much more aesthetically pleasing. However, the icons have changed quite a bit between different versions, which violates consistency. But, overall, Gimp has a pretty good interface.

On the UX side of the coin, there is a lot that could be improved. Can you intuitively tell what each of these icons does? What does the wave icon do?

Commonly used tools and features are often buried in layers of tabs and menus, making the software harder to use than necessary. Some features are not intuitive. For example, when moving layers, the default setting is "Pick a layer or guide" to move, but it is very hard to predict which layer actually moves.

Gimp is a great product but can be frustrating to use at times. The interface functions fine, but it is not always streamlined to accommodate the user. This nicely demonstrates that although the user interface is directly connected to the user experience, user experience is its own beast.

Designing a large complex application is very time-consuming. To make it more manageable, different aspects are assigned to different people or teams. While the UI designer is creating the design, the UX designer could be researching how people will use the product. Their research can then be incorporated into the design and layout.

UI and UX designers work very closely, but on different aspects of the design. The UI design focuses on the concrete aspects of the design: The placement of the buttons and color scheme, for example. At the same time, UX designers ask more abstract questions like whether users will enjoy using a product and whether it will solve the users' needs.

You can have good UI with poor UX and poor UI with good UX. For example, Notepad++ is not terribly attractive, but the simplicity makes it easy to use. Its UI is weak, but its UX is strong.

What Is a UI/UX Designer?

We have established that UI and UX are different things. However, we have also demonstrated that they both are primarily concerned with an application's interface. When working in large teams, there are a lot of advantages to separating these roles. However, when working in small teams, it can be beneficial to combine roles. Earlier, we mentioned that a UI designer can also be a front-end developer. However, the role can also be combined with the UX role.

Both UI and UX designs don't necessarily require any programming. Much of the design work and testing can be done with wireframes and prototypes. This means a UI/UX designer can have a background in design and behavioral science rather than computer science. Thus, a UI/UX designer is great for small teams that want their design to be very user-centered.

Bringing it All Together

The composition of a development team is determined by the needs of a design. Creating a good team requires a good understanding of the different roles and specialties of each member of the team.If you are thinking of getting into web development, an interest in UI and UX will help you decide between becoming a front-end or back-end developer.

The roles of UI designers and UX designers are complimentary, but they do each have different strengths. Understanding their strengths can help you to form the best team.

Categories
News

What Is a Function in Programming? | MakeUseOf

Do you often find yourself copying and pasting your code to reuse in different sections in your program?

If so, you might want to consider using functions. Functions are a very powerful feature of programming languages. They can make code more efficient, easier to read, and elegant.

What Is A Function?

A function is a block of code that performs a task. It can be called and reused multiple times. You can pass information to a function and it can send information back. Many programming languages have built-in functions that you can access in their library, but you can also create your own functions.

When you call a function, the program will pause the current program and execute the function. The function will be read from top to bottom. Once the function is complete, The program continues to run where it had paused. If the function returned a value, that value will be used where the function was called.

How Do You Write A Function?

There are many different ways to write functions. The exact syntax will depend on the language that you are programming in. We will show examples in Python, JavaScript, and C++ to demonstrate a range of programming syntax.

Related: Why Programming Languages Can't Exist Without Functions

Void Functions

The first type of function that we will look at is a void function. This simply means that the function does not return a value. Void functions are used to complete a set of instructions. In these examples, the function we wrote is called helloFunction. The purpose of the function is to output "Hello World".

TIP: give functions names that explain what they do. It will be easier to manage functions and read the code as your program becomes more complex.

Python

def helloFunction():
print("Hello World")
helloFunction()

The keyword def is used in Python to define and create a function. Next, is the name of the function. The instructions in the function follow on the next line after the colon. White space matters in Python, so be sure to indent all the code that you want your function to run. In the example above, the function runs one line of code.

Your keen eyes might have noticed that print() is also a function, but it is called differently than our function. Hold on to that thought right now, we will explore functions will parameters later.

JavaScript

function helloFunction(){
alert("Hello World!");
}
helloFunction();

In JavaScript, the keyword function is used to create functions. Next, we have the name of the function. Any code that falls between the curly brackets is run when the function is called.

White space is not important in JavaScript, but it is customary to indent the code in the function. Indentation makes code easier to read, which is very important as your programs become more complex.

Note: Much like print() in the earlier example, alert() is also a function.

C++

#include <iostream>
using namespace std;
void helloFunction(){
cout << "Hello World!";
}
int main(){
helloFunction();
return 0;
}

Functions are created differently in C++. Instead of a keyword to define a function, the first word describes the type of data that the function will return. In this case, our function does not return any data, so the data is void. Next, we have the function's name. Similar to JavaScript, all the code between the curly brackets is run when the function is called. Also similarly to JavaScript, white space does not affect the function but is good practice.

Did you spot another function in the C++ code? Yes, main() is a function. When you execute a C++ program, you automatically call the main function. When the main function is successfully completed, it returns 0 as it exits the program to signal there were no errors running the program.

Functions That Require Values

Void functions are great if you find that you are writing the same bit of code over and over again. But they can be limiting. They are static and don't change. They always complete the same instructions. One way we can increase their usefulness is to pass different values to the function.

You will have noticed that brackets followed the names of all of our functions. In the brackets, we can declare that data is needed to run our function. Then we can use the data passed to our function in the function. Let's take a look at the previous examples again, but this time pass the phrase that we want to be outputted.

Python

def helloFunction(newPhrase):
print(newPhrase)
helloFunction("Our new phrase")

Now, between the brackets, our function declares that it needs a variable to run. We have named the variable newPhrase and can now use it in our function. When we call the function, we need to pass the requested information by placing it in between the brackets. The same changes were made in JavaScript.

JavaScript

function helloFunction(newPhrase){
alert(newPhrase);
}
helloFunction("Our new phrase");

C++

#include <iostream>
using namespace std;
void helloFunction(string newPhrase){
cout << newPhrase;
}
int main(){
helloFunction("Our new Phrase");
return 0;
}

Our C++ function required a bit more information. We know that your function wants string data, but that's not good enough for C++. When you create your function you have to specify what type of data your function requires. If you do not send the correct type of data, the function will create an error.

This might seem a little annoying, but strict languages can often save you headaches. If you write a function in JavaScript that requires an integer, but the number is sent as a string, it can create a bug that is very hard to track down.

Related: 5 Functional Programming Languages You Should Know

Functions That Return a Value

The final function ability that we will cover is returning data. This is particularly valuable when you want to alter data before you use it. Although you could write that inline, if you will use the same calculations many times, like converting imperial to metric, it might make more sense to write it as a function. Our example will be simpler. Our function will require two integers and will return the sum.

Python

def addingFunction(a, b):
return a + b
print(addingFunction(2, 4))

In this example, our function requires two variables instead of one. We indicate that by separating our variable names with a comma. The keyword return tells the function to return the following data, in this case, 2 + 4, or 6. We call the function inside the print() function.

Once our program got to that line, it would have paused, ran our function, and then continued as if addingFunction(2, 4) was actually just the returned value 6.

JavaScript

The JavaScript code is very similar to the Python code. The primary difference is that the function is called in an alert.

function addingFunction(a, b){
return a + b;
}
alert(addingFunction(2, 4));

C++

#include <iostream>
using namespace std;
int addingFunction(int a, int b){
return a + b;
}
int main(){
cout << addingFunction(2, 4) ;
return 0;
}

The C++ code runs similarly, but as usual, requires a bit more information. First, we have to say what type of data our function will return. You will see that void has been changed to int. This means that instead of returning no data, our function will return an integer. Beyond that, the code is similar to the code we have already explored.

Manage Your Functions

A fun thing about functions is that functions can call other functions. They can even call themselves! But with great power comes great responsibility. Do not go crazy creating code with functions that call other functions that call yet more functions.

As mentioned, every time a function is called, the program pauses while it runs the function. This means that the program is being held in active memory. If you call several more functions without completing them, you are using more active memory. If you are not careful, your program can get out of hand.

Categories
News

6 Software Development Steps All Programmers Should Know

Starting a new software project can be overwhelming. It can be helpful to break the process into smaller, more manageable steps. Traditionally, software development has been broken into six steps. Using this process can make a large project less intimidating.

What Is Software Development?

Before we dive into the process, it will be helpful to define software development. It can be tempting to think that a small project doesn't really qualify as "software development". However, no matter how big or small your project is, if you are designing a program, you are engaging in software development.

Simply put, software development is the process of creating and coding software to meet some need. It could be the needs of customers, or a personal need, such as automating a task. The program could be large or small. But, all projects benefit by breaking the project down into a series of steps.

Software Development Steps

1. Needs Assessment

As mentioned, software development solves a need. Thus, the first step of any project is clearly identifying the need that you are trying to solve. On large projects, this could involve market research and meeting with stakeholders. A smaller project might just require making a list of must-have features.

This is the most important step in the process. Without a clear understanding of what is required to solve your problem, it will be difficult to design an adequate solution. Having a clear vision of a product can also help to keep your project on track. As you begin to design your project it might be tempting to add features that are not needed but are wanted. This is called scope creep and it can derail a project.

Related: The Best Project Management Tips for Beginners

2. Design

If you love to program, it can be tempting to jump into the code as soon as you have a good idea. But your project will run much smoother if you take the time to design your software first. This step is analogous to writing an outline before you begin to write a paper. It serves to organize your thoughts. Most of your problem solving should be complete in this step so that when you start coding, there should be few complications.

In this step, there are several things you will want to consider. If your software project requires an interface, develop a prototype that outlines the look and functionality of the interface. If the project uses a database, design the tables, and map out the relationships between them.

All software development will require writing algorithms. Create flow charts that outline the program flow and describe any complex algorithms, like functions or methods.

3. Coding

This is arguably the most straightforward and fun step.

In this step, you write the code to create the software. After the needs of the project have been clearly defined, and the design outlined, this step should be straightforward---in theory at least. Realistically, issues may arise in this stage, but the more planning completed before programming, the smoother it goes.

4. Testing

After you write the code, it must be tested. You need to validate that the code works as expected and meets the needs it was designed to meet. In smaller projects, this step can be fairly straightforward and primarily involve debugging the software. In larger projects, this could involve testing the software with focus groups to refining the design and requirements of the software.

The order of this step can vary. For example, Test Driven Development creates a script to test the software first. Coding is considered complete when it passes the test. Conversely, if you use an iterative design method, testing will be integrated into several design stages.

Related: The Best Free Online HTML Editors to Test Your Code

5. Implementation

Once the software passes testing, it is ready to be deployed. At this stage, the software should be fully functional and can be released, and/or used. Large projects may be released in stages, which is called a staggered release.

When the software is placed into the hands of users, they often find issues and bugs that were not discovered during testing. A staggered release makes responding to these issues manageable.

6. Maintenance

The maintenance step is another crucial phase. Once the software is used, it might not quite meet the need it was designed for, new features might be released, or new bugs may be discovered. All of this requires monitoring and revising the software.

Development Methodologies

Although the above steps make software development seem linear, it doesn't have to be. There are many different ways to approach software development. The two most well-known methods are waterfall and agile software development.

Waterfall

Waterfall development was the traditional way to manage a project. It involves completing software development steps in sequential order. Each step would be completely finished before the team would move on to the next step.

This method is easy to manage and can work well for small software projects. Because the process is straightforward and each step has clear goals, it is easy to manage. It is suitable for projects that have a clear goal and easily understandable requirements.

The waterfall method does not work well when a project is complex, or if the requirements are not clear. It can be difficult to change the design of the software using this method. Because the steps are followed sequentially, it is difficult to go back a step, which makes it difficult to respond to issues that arise or pivot the design.

Agile

Agile was designed to address many of the shortcomings of the waterfall approach. Instead of moving from one step to the next until you are done, the process is cyclical. The project is incrementally created in a series of development cycles. Testing is central to the process. Each cycle incorporates the lessons learned from testing. This cyclical approach builds re-design into the process of software development.

Related: How to Use Agile Project Management Principles to Organize Your Life

The benefit of agile is that it allows the project to evolve to address issues discovered during testing. This is a great approach for user-focused design. Despite the development process being more complex, it can also be more cost-effective for large projects. Problems can be addressed quickly as they arise and it is easier to change the design in response to issues that arise.

Software Development

There are many considerations when beginning a new software project. The purpose and scope of the project will dictate the best software development method. However, all approaches are based on the same steps. If you are new to programming, it will always be tempting to jump straight into coding. But taking the time to plan your project is time well spent.

Categories
News

Should You Be a Programmer? 3 Programming Aptitude Tests to Help You Decide

Aptitude tests can be great tools to help you align your strengths with a career path. If you have been considering a programming career, you might want to try taking some programming aptitude tests. They can give you insight into the type of skills that programmers use regularly. The tests will also help you identify if you excel at those skills.

What Are Aptitude Tests?

Aptitude tests are designed to predict whether you will succeed at a given task. Everyone has strengths and weaknesses. Everyone has different educational backgrounds, interests, and hobbies. Therefore it is natural for some things to come easier to some than others. Aptitude tests identify if a new skill will be easy for you to acquire.

They are most commonly used to predict whether someone will succeed in a given career. But, they can also assess how well people learn different subjects. Programming aptitude tests are a bit of both. They are designed to gauge success in programming by determining how well you can solve problems requiring mathematical knowledge and logical reasoning.

If you are interested in programming or starting a computer science degree, you may want to try some free programming aptitude tests. They will give you a taste of the type of problems you will need to solve as a programmer.

ComputerAptitude.com LLC

ComputerAptitude.com LLC offers a very short sample aptitude test. The test is not timed and consists of five questions. This is a great option if you are curious about programming aptitude tests but do not have a lot of time to complete one.

You do not require an account, once you complete the questions, you can click a button to see your results. The test will tell you your score and show you the correct answers.

The questions primarily test your logical reasoning, but there are also some mathematical questions. A strength of this test is that it tests your ability to read a flowchart. Flowcharts are often used in programming when designing algorithms.

The site also offers a longer test that has 25 questions that must be completed in 25 minutes. That test does require you to create an account. However, at the time of this writing, there is a bug that breaks the signup form.

Related: The Best Free Flowchart Software for Windows

University of Kent Computer Programming Aptitude Test

The University of Kent's Careers and Employment Services website offers a Computer Programming Aptitude Test. The test is timed. You are given 25 minutes to answer 26 questions. The test begins with three untimed practice questions, so it will take a little longer than 25 minutes to complete. You do not need to create an account or provide any information to review your results.

If you are interested in completing this test, do not scroll too far down the page before you begin. The answers to the questions appear on the same page. Although it is nice to be able to see how to solve the problems, this test would have been better if the answers were hidden until the test was completed. This does have a benefit though, as if you do not have time to take the test, peeking at the answers will give you an idea of the skills involved in programming.

The test assesses logical reasoning, problem-solving, pattern recognition, and the ability to follow complex procedures. The questions are fairly simple but are difficult to complete within the timeframe provided. The test will give you a good sense of how well you can program in a high-stress environment.

Related: The Best Calming Apps to Relax, Destress, and Clear Your Mind

This aptitude test is not well suited to all people. If you have test anxiety, you may do poorly on the test because it is timed. The test then may not accurately reflect your ability. There is a section where you need to identify which blocks of random characters are different. This could be difficult for someone with dyslexia and isn't typical of how problems are solved in practice.

Programming Skill Aptitude Online Test

Training and education site Programming Skills offers aptitude tests and programming language-specific tests.

There are ten different timed aptitude tests. To complete the test, you need to answer 20 questions in 25 minutes. All of the tests assess the same skills but have different questions.

Each test primarily assesses numerical problem-solving. It'll give you a good idea of whether you excel in that skill, but they do not assess other skills necessary to succeed as a programmer. These tests would be best suited for someone who enjoys solving math problems or someone who wants to assess their mathematical abilities.

Related: Cool Math Games for Kids

Once you complete a test, you will be shown your score and the answer to all of the questions. Any questions that involved problem-solving will have a description explaining how to solve the problem. You do not need to provide any personal information to review your results.

Are Programming Aptitude Tests Helpful?

The answer to this question will depend on what you hope to learn from an aptitude test. Their greatest strength is that they give you a sense of what types of skills programmers need to be successful. If you do not enjoy slogging through a bunch of problem-solving questions, you probably won't enjoy being a programmer.

If you are interested in becoming a programmer but did not do well on an aptitude test, you shouldn't take that as a sign to quit. Tests do not simulate the act of programming. Test anxiety can decrease your score. There are also many tools that make aspects of the job easier and can help you organize your thoughts when problem-solving.

Aptitude tests are best suited for someone that is considering entering a computer science degree. Degree programs generally require a high level of mathematical skills, which is the emphasis of many programming aptitude tests. If you are learning for fun, there are many other skills that are more important, such as creativity. An alternative to aptitude tests is coding challenges and competitions, some of which can lead to cash prizes or even job opportunities.

Learning any new skill takes time. Programming is no different. Even if you are struggling with the skills now, it does not mean that you will not improve over time. These tests can be a great tool to assess your skill development.

Categories
News

A Beginner’s Guide To Raspberry Pi Breadboarding With The Game Simon

A breadboard allows you to create circuits without having to solder anything. It is a great tool to experiment with electronics, but it can be intimidating. Having a project to build can help you stay motivated while you learn.

There are several simple games that make great Raspberry Pi beginner projects. An easy one to get you started is the game Simon. Simon is a memory game in which a series of lights flash in random order, and the player must remember the sequence. As the player progresses, the length of the sequence grows.

Required Components

To get started, you will need the following things:

  1. A Raspberry Pi
  2. A microSD card flashed with Raspbian OS
  3. 4 x LEDs of different colors
  4. 4 x resistors (anything from 220 Ohm to 1 Kilo-Ohm)
  5. 4 x buttons
  6. 1 x breadboard
  7. Jumper cables for connecting everything up

You can use any Raspberry Pi for this project, but the Pi Zero models do not connect to breadboards as easily without some soldering. Whichever model you use, you will also need a power source, monitor, keyboard, and mouse.

If you have never set up a Raspberry Pi before, you can learn how to get everything ready for this tutorial in the Raspberry Pi beginner guide.

You'll be writing Python code in this tutorial, and you can use any text editor to write it, but you might find a code editor easier. There are several already installed on the Raspberry Pi OS, and Thonny is designed to be easy for beginners. Whichever one you use, you'll need to be able to save and run your code to follow this tutorial.

Getting Started With a Breadboard

If you have never used a breadboard before, you may want to start by reading a breadboard tutorial. Understanding how a breadboard works will help you understand how to create circuits.

The Raspberry Pi has two rows of general-purpose input/output (GPIO) pins. These pins allow you to connect components to your Raspberry Pi. Some pins send information, others provide power, and some ground your electronics.

We will begin by adding a LED light to our breadboard. If you have never worked with LED lights on a breadboard before, you might want to read a tutorial that will explain how it works in more depth.

Begin by connecting a GPIO pin to your board. It doesn't matter which pin, as long as it is a GPIO pin and not a power or ground pin. Above is a chart of the GPIO pins, which will help you determine which pin to use. This tutorial uses pin number 18, which is also labeled GPIO 24.

The pin will supply some power to the breadboard and allow the Raspberry Pi to communicate with components on the board. Then connect pin number 6 on the Pi to the ground rail of the breadboard. This will ground the board and allow us to create circuits.

The power coming from the Raspberry is too high to connect the LED directly. Using a resistor brings the power level down and prevents the LED from burning out. Connect one side of the resistor to the same line the GPIO pin is plugged into and the end into the other side of the breadboard. Then place the positive side of the LED after the resistor. The negative end of the LED can be connected directly to the negative rail. The end result should look like the diagram above. Check your wiring thoroughly and turn your Pi on. The LED should light up.

Now, you've made a circuit using your Raspberry Pi that you can control using code.

Using Python Code to Control LEDs

This tutorial takes you through the code in steps, but if you want to refer to the finished code at any time, it's available on Pastebin.

Right now, the power is going to the LED, but we want to control when it turns on and off. The following Python code will allow us to talk to the board.


import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
red = 18
GPIO.setup(red, GPIO.OUT)
GPIO.output(red, GPIO.LOW)

The first few lines set things up. The Raspberry Pi GPIO library is imported. The as GPIO just lets us refer to RPi.GPIO as GPIO to save a bit of typing. The GPIO pin mode is set to BOARD. You do not have to use this setting, but it can be easier to refer to the pins by their order in the GPIO rows.

Finally, we set warnings to false. This will stop unnecessary warnings.

The next three lines control the LED. The red LED is attached to GPIO pin 18. Instead of remembering that, the variable red will store the location. Next, GPIO.setup tells our program that it is sending information out to the red pin. Finally, we set the GPIO.output on the red pin to low. When you run this program, the light will turn off. To turn it back on, switch GPIO.LOW to GPIO.HIGH, and run the program again.

Save the code, and click run to see it in action. If there is no run button in your code editor, save it and run python myfilename.py in the terminal window. You'll need to navigate to the same directory as your new Python file first. Check the Raspberry Pi cheat sheet if you aren't sure how.

Adding More Than One LED

To create the game Simon, we need four lights of different colors. The same steps that you used to set up the red LED can be used to set up the other three. Your wiring should look like the diagram below:

Your code should look like this:


import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
red = 18
yellow = 22
green = 24
blue = 26
GPIO.setup(red, GPIO.OUT)
GPIO.setup(yellow, GPIO.OUT)
GPIO.setup(green, GPIO.OUT)
GPIO.setup(blue, GPIO.OUT)
GPIO.output(red, GPIO.HIGH)
GPIO.output(yellow, GPIO.HIGH)
GPIO.output(green, GPIO.HIGH)
GPIO.output(blue, GPIO.HIGH)

Once you have tested the LEDs, set the GPIO.output to GPIO.LOW to turn each one off again.

Although the color of the wires that you use does not matter, try to use colors that have meaning to you to help you read the board easier. For example, black wires are often used for ground wires. In this circuit, you might want to match the color of the wire to the color of the LED light.

Controlling LEDs With Buttons

Begin by adding a button to your board. The button will need to be connected to both the ground and a GPIO pin. The circuit should look something like this:

To make the button control an LED, we need to add to our code. Setting up the button is similar to setting up an LED, except that the GPIO pin is set to be an input, not an output. This code also sets up the internal pull-up resistor on the Pi, which is needed to make the button behave correctly.

GPIO.setup(32, GPIO.IN, pull_up_down=GPIO.PUD_UP)

Now we need code that checks to see if the button has been pressed.


game = True
while game:
redButtonState = GPIO.input(32)
if redButtonState == 0:
GPIO.output(red, GPIO.HIGH)
time.sleep(1)
GPIO.output(red, GPIO.LOW)

We want our program to keep checking if a button is pressed, so we use a while loop. Because the loop will never be false, it keeps running and checking the button until we end the program manually by pressing the stop button or using the keyboard shortcut Ctrl + c.

Next, to make it easier to reference the input our button GPIO pin is sending us, we save that information in the variable redButtonState. If our button input changes to 0, we know the button was pressed.

If the button is pressed, the red LED will turn on. Then, after a second, the LED will turn off. To time this, we use the time.sleep(1) function. To make this work, you will need to import the time library at the top of your script.

Once one button is working, you can add three more, one for each LED. Your code should look like this:


import random
import time
import RPi.GPIO as GPIO
GPIO.setmode (GPIO.BOARD)
GPIO.setwarnings(False)
red = 18
yellow = 22
green = 24
blue = 26
GPIO.setup(red, GPIO.OUT)
GPIO.setup(yellow, GPIO.OUT)
GPIO.setup(green, GPIO.OUT)
GPIO.setup(blue, GPIO.OUT)
GPIO.setup(32, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(36, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(38, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(40, GPIO.IN, pull_up_down=GPIO.PUD_UP)
game = True
while game:
redButtonState = GPIO.input(32)
if redButtonState == 0:
GPIO.output(red, GPIO.HIGH)
time.sleep(1)
GPIO.output(red, GPIO.LOW)

yellowButtonState = GPIO.input(36)
if yellowButtonState == 0:
GPIO.output(yellow, GPIO.HIGH)
time.sleep(1)
GPIO.output(yellow, GPIO.LOW)
greenButtonState = GPIO.input(38)
if greenButtonState == 0:
GPIO.output(green, GPIO.HIGH)
time.sleep(1)
GPIO.output(green, GPIO.LOW)
blueButtonState = GPIO.input(40)
if blueButtonState == 0:
GPIO.output(blue, GPIO.HIGH)
time.sleep(1)
GPIO.output(blue, GPIO.LOW)

Your board should look something like this:

All of the electronics are now in place. If you have any problems, check through your code for any mistakes. Remember, you can download the full code from Pastebin if you get stuck!

Creating the Game

This project has already covered all of the basics you need to know to start using a breadboard. But turning these skills into a game will really showcase what you can do!

In Simon, a player sees a series of lights flash and has to remember the pattern. It starts easily with only one light. Each level adds a random light to the pattern to make the game harder.

Creating the Pattern

This step is fairly simple. One array will hold our light pattern. A second array will store the GPIO pins for our lights. Every game loop, a new random light will be added to the end of the pattern array. We use the random.randint() function to choose a number between 0 and 3, representing the 4 LEDs.


pattern = []
lights = [red, yellow, green, blue]
while game:
pattern.append(random.randint(0,3))

Next, we have to light up the lights to show the pattern.

while game:
pattern.append(random.randint(0,3))

for x in pattern:
GPIO.output(lights[x], GPIO.HIGH)
time.sleep(1)
GPIO.output(lights[x], GPIO.LOW)
time.sleep(0.5)

It is important to pause between two lights. It makes it easier to see if the same light is used back-to-back in the pattern.

Getting Player Input

Next, the game has to wait for the player to guess the order of the lights. The program has to both check each light in the pattern and wait for the player to press a button. This requires nested loops:


for x in pattern:

waitingForInput = True

while waitingForInput:
redButtonState = GPIO.input(32)
yellowButtonState = GPIO.input(36)
greenButtonState = GPIO.input(38)
blueButtonState = GPIO.input(40)

if redButtonState == 0:
GPIO.output(red, GPIO.HIGH)
waitingForInput = False
time.sleep(1)
GPIO.output(red, GPIO.LOW)

if yellowButtonState == 0:
GPIO.output(yellow, GPIO.HIGH)
waitingForInput = False
time.sleep(1)
GPIO.output(yellow, GPIO.LOW)

if greenButtonState == 0:
GPIO.output(green, GPIO.HIGH)
waitingForInput = False
time.sleep(1)
GPIO.output(green, GPIO.LOW)

if blueButtonState == 0:
GPIO.output(blue, GPIO.HIGH)
waitingForInput = False
time.sleep(1)
GPIO.output(blue, GPIO.LOW)

Most of the code above is reusing the code we wrote to test the buttons.

Related: 6 Reasons Why Python Is the Programming Language of the Future

Check the Player's Input

From here, it is pretty easy to check if the player has entered the right pattern. Every time they press a button, the game can check to see if that was the correct button. To do this, add another if statement to each button input:


if redButtonState == 0:
GPIO.output(red, GPIO.HIGH)
waitingForInput = False
if x != 0:
game = False
time.sleep(1)
GPIO.output(red, GPIO.LOW)

The variable x from our for loop has the number of the next light. The red LED light is in the first position, or number 0. If the player pressed the red LED button when we have a 0 in our pattern, they are right! If not, they lose the game. Setting the variable game to false will stop our game loop and end the program.

Congratulations! You Built a Game From Scratch!

Creating a game added much more code to this project than just adding LEDs and buttons. Working towards a final project that you can show your friends and family can help keep you motivated.

This game is fairly simple. Challenge yourself to improve upon the basic design. Perhaps the lights could flash if the player loses. Maybe you want to challenge yourself to add sounds to the game. Your imagination is the only limit!

Okay, that and the hardware you have to hand.

Categories
News

What Is DMCA and What Does It Mean? | MakeUseOf

If you have spent any time on the internet, you have probably come across the acronym DMCA. Perhaps, you have even had some of your content taken down on a DMCA claim. So, what is DMCA, and what does DMCA stand for?

What Is DMCA?

DMCA stands for Digital Millennium Copyright Act. As the name implies, it was created around the turn of the last millennium. Specifically, it was enacted in 1998. The DMCA is an American law that criminalizes the unlawful use of copyrighted materials.

Despite that it is an American law, the DMCA has wide-reaching effects. This is because although websites can be accessed globally, they are bound to the law of the country where their servers are located. For example, YouTube's servers are located in the US. So, even if you are Canadian, any content you upload to YouTube is governed by US law, not Canadian law.

The DMCA was created to prevent piracy. By the late 90s, new technologies, such as the internet and CD burners, made it easier than ever to pirate content. If you are old enough to remember things such as Napster or Limewire, you know just how easy it was! This made media industries concerned that there were not enough laws to protect their industry from piracy.

Related: 7 Underground Torrent Sites for Getting Uncensored Content

Once the DMCA was enacted, it gave individuals and companies a way to protect their content. If a content creator sees their work being unlawfully used on a website hosted on an American server, they can make a DMCA claim. A DMCA claim requires that the server hosting the content remove or disable access to the content.

The DMCA applies to a variety of content, including:

  • Written text
  • Pictures
  • Artwork
  • Music
  • Videos
  • Software

What Is A DMCA Notice?

The person accused of copyright infringement receives a DMCA Notice. DMCA notices will note what content is being claimed and who is claiming the infringement.

If you receive a DMCA notice, it is really important to think about whether you used the content lawfully. If you haven't, remove the content right away. Generally, removing the content will resolve the DMCA violation. However, the content creator does have the right to sue for damages. So, receiving a DMCA notice should not be taken lightly.

If you believe that you did not use the content unlawfully, then you can submit a counter-notice. Unfortunately, the DMCA is sometimes abused and submitted against people who have not violated the DMCA. In these situations, a counter-claim allows the accused to defend themself. However, the content should still be removed until the dispute is settled.

The complainant will have 14 days to either stop pursuing the takedown request or file a lawsuit. Thus, submitting a counterclaim is risky and should be carefully considered.

Can You Use Content Lawfully?

Despite all these rules, you will see people borrow content from people all of the time. Why is that still allowed? You can use copyrighted material under fair use. Fair use includes:

  • News Reporting
  • Commentary
  • Research
  • Criticism
  • Scholarship
  • Parody
  • Teaching

The purpose of exempting fair use is to balance the need to protect creators with the public good of building on and responding to the created content. However, fair use does complicate things a bit. It can become hard to determine if the content was used fairly. Four factors are used to judge whether content falls under fair use.

Related: How to Get Started Using Spotify Duo

1: The Purpose of the Content

Using content in fair use requires you to transform it into something different than the original creation. The purpose of the new content must be distinct from the original content.

For example, Screen Junkies uses clips from movies to create their "Honest Trailers" series. If they were just posting clips of movies, that would not be fair use. But they are creating something completely new. The purpose of the videos is to comment on the quality of the movies. That is very different than the purpose of creating the movie, which is to tell a story.

2: Type of Content

Facts and ideas cannot be copyrighted. This exemption is to ensure that important ideas and information is always available to the public. Granted, this exemption can allow for some questionable rulings.

For example, if you wrote the classic movie Gremlins, you could not stop someone from using the same premise to make Critters. If the script dialogue is different, it falls under fair use. On the other hand, would you have wanted Akira Kurosawa to be able to kibosh production of Star Wars?

3: Amount of Content Used

The amount of content you borrow is also a factor. You are only allowed to use as much content as you need to complete your purpose. Going back to the earlier Screen Junkies example, their videos only use clips of the movies highlighting their point. If they play 15 minutes of the movie to mock one scene, their videos may no longer qualify as fair use.

4: Damages Caused

It is not fair to interfere with the original creator’s ability to profit off of their creation. If you use their content to create something that could be used as a substitute for the original creation, it will fall into this category.

For example, if someone posted informational content on YouTube, you could not edit that content down to a summary and then repost it. You would be stealing the original creator’s YouTube views.

Related: 4 Ways to Watermark Your Videos

This does not cover damaging profits from negative reviews of a product. That would fall under criticism, which is considered fair use.

DMCA In A Nutshell

The DMCA stands for the Digital Millennium Copyright Act. It was created in the late 90s to address new technology that made piracy easier. It protects creators of a variety of different artistic mediums. Its purpose is to stop the unfair use of content. Fair use still allows people to use content to create new content if it transforms the final product into something new that adds value to the public.