Technology Articles
Technology. It makes the world go 'round. And whether you're a self-confessed techie or a total newbie, you'll find something to love among our hundreds of technology articles and books.
Articles From Technology
Filter Results
Article / Updated 12-09-2024
As you delve deeper into the realm of prompt engineering, you find out that the effectiveness of a prompt can vary greatly depending on the application. Whether you’re using AI for creative writing, data analysis, customer service, or any other specific use, the prompts you use need to be tailored to fit the task at hand. The art in prompt engineering is matching your form of communication to the nature of the task. If you succeed, you’ll unlock the vast potential of AI. For instance, when engaging with AI for creative writing, your prompts should be open-ended and imaginative, encouraging the AI to generate original and diverse ideas. A prompt like “Write a story about a lost civilization discovered by a group of teenagers” sets the stage for a creative narrative. In contrast, data analysis requires prompts that are precise and data-driven. Here, you might need to guide the AI with specific instructions or questions, such as “Analyze the sales data from the last quarter and identify the top-performing products.” You may need to include that data in the prompt if it isn’t already loaded into the training data, retrieval-augmented generation (RAG), system or custom messages, or a specialized GPT. In any case, this type of prompt helps the AI focus on the exact task, ensuring that the output is relevant and actionable. The key to designing effective prompts lies in understanding the domain you’re addressing. Each field has its own set of terminologies, expectations, and objectives. For example, legal prompts require a different structure and language than those used in entertainment or education. It’s essential to incorporate domain-specific knowledge into your prompts to guide the AI in generating the desired output. Following are some examples across various industries that illustrate how prompts can be tailored for domain-specific applications: Legal domain: In the legal industry, precision and formality are paramount. Prompts must be crafted to reflect the meticulous nature of legal language and reasoning. For instance, a prompt for contract analysis might be, “Identify and summarize the obligations and rights of each party as per the contract clauses outlined in Section 2.3 and 4.1.” This prompt is structured to direct the AI to focus on specific sections, reflecting the detailed-oriented nature of legal work. Healthcare domain: In healthcare, prompts must be sensitive to medical terminology and patient privacy. A prompt for medical diagnosis might be, “Given the following anonymized patient symptoms and test results, what are the potential differential diagnoses?” This prompt respects patient confidentiality while leveraging the AI’s capability to process medical data. Education domain: Educational prompts often aim to engage and instruct. A teacher might use a prompt like, “Create a lesson plan that introduces the concept of photosynthesis to 5th graders using interactive activities.” This prompt is designed to generate educational content that is age-appropriate and engaging. Finance domain: In finance, prompts need to be data-driven and analytical. A financial analyst might use a prompt such as, “Analyze the historical price data of XYZ stock over the past year and predict the trend for the next quarter based on the moving average and standard deviation.” This prompt asks the AI to apply specific financial models to real-world data. Marketing domain: Marketing prompts often focus on creativity and audience engagement. A marketing professional could use a prompt like, “Generate a list of catchy headlines for our new eco-friendly product line that will appeal to environmentally conscious consumers.” This prompt encourages the AI to produce creative content that resonates with a target demographic. Software development domain: In software development, prompts can be technical and require understanding of coding languages. A prompt might be, “Debug the following Python code snippet and suggest optimizations for increasing its efficiency.” This prompt is technical, directing the AI to engage with code directly. Customer service domain: For customer service, prompts should be empathetic and solution oriented. A prompt could be, “Draft a response to a customer complaint about a delayed shipment, ensuring to express understanding and offer a compensatory solution.” This prompt guides the AI to handle a delicate situation with care. By understanding the unique requirements and language of each domain, you can craft prompts to effectively guide AI in producing the desired outcomes. It’s not just about giving commands; it’s about framing them in a way that aligns with the goals, terms, and practices of the industry in question. As AI continues to evolve, the ability to engineer precise and effective prompts becomes an increasingly valuable skill across all sectors. 15 tips and tricks for better AI prompting Although GenAI may seem like magic, it takes knowledge and practice to write effective prompts that will generate the content you’re looking for. The following list provides some insider tips and tricks to help you optimize your prompts to get the most out of your interactions with GenAI tools: Know your goal. Decide what you want from the AI — like a simple how-to or a bunch of ideas — before you start asking. Get specific. The clearer you are, the better the AI can help. Ask “How do I bake a beginner's chocolate cake?” instead of just “How do I make a cake?” Keep it simple. Use easy language unless you’re in a special field like law or medicine where using the right terms is necessary. Add context. Give some background if it's a special topic, like tips for small businesses on social media. Play pretend. Tell the AI to act like someone, like a fitness coach, to get answers that fit that role. Try again. If the first answer isn't great, change your question a bit and ask again. Show examples. If you want something creative, show the AI an example to follow, like asking for a poem like one by Robert Frost. Don't overwhelm. Keep your question focused. If it's too packed with info, it gets messy. Mix it up. Try asking in different ways, like with a question or a command, to see what works best. Embrace the multimodal functionality. Multimodal functionality means that the GenAI model you’re working with can accept more than one kind of prompt input. Typically, that means it can accept both text and images in the input. Understand the model’s limitations. GenAI is not infallible and can still produce errors or “hallucinate” responses. Always approach the AI’s output with a critical eye and use it as a starting point rather than the final word on any subject. Leverage the enhanced problem-solving abilities. GenAI’s enhanced problem-solving skills mean that you can tackle more complex prompts. Use this to your advantage when crafting prompts that require a deep dive into a topic. Keep prompts aligned with AI training. For example, remember that GPT-4, like its predecessors, is trained on a vast dataset up to a certain point in time (April 2023 at the time of this writing). It doesn’t know about anything that happened after that date. If you need to reference more recent events or data, provide that context within your prompt. Experiment with different prompt lengths. Short prompts can be useful for quick answers, while longer, more detailed prompts can provide more context and yield more comprehensive responses. Incorporate feedback loops. After receiving a response from your GenAI application, assess its quality and relevance. If it hit — or is close to — the mark, click on the thumbs-up icon. If it’s not quite what you were looking for, provide feedback in your next prompt by clicking on the thumbs-down icon. This iterative process can help refine the AI’s understanding of your requirements and improve the quality of future responses. By keeping these tips in mind and staying informed about the latest developments in the capabilities of various GenAI models and applications, you’ll be able to craft prompts that are not only effective but also responsible and aligned with the AI’s strengths and limitations. How to use prompts to fine-tune the AI model The point of prompt engineering is to carefully compose a prompt that can shape the AI’s learning curve and fine-tune its responses to perfection. In this section, you dive into the art of using prompts to refine the GenAI model, ensuring that it delivers the most accurate and helpful answers possible. In other words, you discover how to use prompts to also teach the model to perform better for you over time. Here are some specific tactics: When you talk to the AI and it gives you answers, tell it if you liked the answer or not. Do this by clicking the thumbs up or thumbs down, or the + or – icons above or below the output. The model will learn how to respond better to you and your prompts over time if you do this consistently. If the AI gives you a weird answer, there's a “do-over” button you can press. It's like asking your friend to explain something again if you didn't get it the first time. Look for “Regenerate Response'’ or some similar wording (term varies among models) near the output. Click on that and you’ll instantly get the AI’s second try! Think of different ways to ask the AI the same or related questions. It's like using magic words to get the best answers. If you're really good at it, you can make a list of prompts that others can use to ask good questions too. Prompt libraries are very helpful to all. It’s smart to look at prompt libraries for ideas when you’re stumped on how or what to prompt. Share your successful prompts. If you find a super good way to ask something, you can share it online (at sites like GitHub) with other prompt engineers and use prompts others have shared there too. Instead of teaching the AI everything from scratch (retraining the model), you can teach it a few more new things through your prompting. Just ask it in different ways to do new things. Over time, it will learn to expand its computations. And with some models, what it learns from your prompts will be stored in its memory. This will improve the outputs it gives you too! Redirect AI biases. If the AI says something that seems mean or unfair, rate it a thumbs down and state why the response was unacceptable in your next prompt. Also, change the way you ask questions going forward to redirect the model away from this tendency. Be transparent and accountable when you work with AI. Tell people why you're asking the AI certain questions and what you hope to get from it. If something goes wrong, try to make it right. It's like being honest about why you borrowed your friend's toy and fixing it if it breaks. Keep learning. The AI world changes a lot, and often. Keep up with new models, features, and tactics, talk to others, and always try to get better at making the AI do increasingly more difficult things. The more you help GenAI learn, the better it gets at helping you! What to do when AI goes wrong When you engage with AI through your prompts, be aware of common pitfalls that can lead to biased or undesirable outcomes. Following are some strategies to avoid these pitfalls, ensuring that your interactions with AI are both effective and ethically sound. Recognize and mitigate biases. Biases in AI can stem from the data it was trained on or the way prompts are structured. For instance, a healthcare algorithm in the United States inadvertently favored white patients over people of color because it used healthcare cost history as a proxy for health needs, which correlated with race. To avoid such biases, carefully consider the variables and language used in your prompts. Ensure they do not inadvertently favor one group over another or perpetuate stereotypes. Question assumptions. Wrong or flawed assumptions can lead to misguided AI behavior. For example, Amazon’s hiring algorithm developed a bias against women because it was trained on resumes predominantly submitted by men. Regularly review the assumptions behind your prompts and be open to challenging and revising them as needed. Avoid overgeneralization. AI can make sweeping generalizations based on limited data. To prevent this, provide diverse and representative examples in your prompts. This helps the AI understand the nuances and variations within the data, leading to more accurate and fair outcomes. Keep your purpose in sight. Losing sight of the purpose of your interaction with AI can result in irrelevant or unhelpful responses. Always align your prompts with the intended goal and avoid being swayed by the AI’s responses into a direction that deviates from your original objective. Diversify information sources. Relying on too narrow a set of information can skew AI responses. Ensure that the data and examples you provide cover a broad spectrum of scenarios and perspectives. This helps the AI develop a well-rounded understanding of the task at hand. For example, if the AI is trained to find causes of helicopter crashes and the only dataset the AI has is of events when helicopters crash, it will deduce that all helicopters crash which in turn will render skewed outputs that could be costly or even dangerous. Add data on flights or events when helicopters did not crash, and you’ll get better outputs because the model has more diverse and more complete information to analyze. Encourage open debate. AI can sometimes truncate debate by providing authoritative-sounding answers. Encourage open-ended prompts that allow for multiple viewpoints and be critical of the AI’s responses. This fosters a more thoughtful and comprehensive exploration of the topic. Be wary of consensus. Defaulting to consensus can be tempting, especially when AI confirms our existing beliefs. However, it’s important to challenge the AI and yourself by considering alternative viewpoints and counterarguments. This helps in uncovering potential blind spots and biases. Check your work. Always review the AI’s responses for accuracy and bias. As with the healthcare algorithm that skewed resources toward white patients, unintended consequences can arise from seemingly neutral variables. Rigorous checks and balances are necessary to ensure the AI’s outputs align with ethical standards.
View ArticleArticle / Updated 11-20-2024
Zero Risk application security provides comprehensive protection against potential threats, ensuring the integrity, confidentiality, and availability of your vital data and systems. This approach integrates automated risk analysis, stringent access provisioning controls, and continuous monitoring to prevent unauthorized access and vulnerabilities. The goal is to neutralize potential threats before they cause harm, which helps maintain the highest levels of visibility, security, and compliance. Aligning your organization’s Zero Risk strategies with established cybersecurity and regulatory compliance frameworks is a necessity. The goal is to create a robust security posture that not only protects your assets but also ensures you meet the critical standards set by regulatory bodies. Understanding the compliance landscape Before you can align your Zero Risk strategies with compliance frameworks, you must understand the landscape. Two of the most significant regulatory frameworks in this realm are the Sarbanes-Oxley Act (SOX) and the General Data Protection Regulation (GDPR). SOX focuses on financial reporting and corporate governance, while GDPR is concerned with data protection and privacy for individuals within the European Union. The National Institute of Standards and Technology (NIST) also provides a risk management framework that can be leveraged to align with Zero Risk strategies. This framework helps your organization manage and mitigate risks in a comprehensive and repeatable manner, ensuring that cybersecurity remains a dynamic and integral part of your organization’s culture and business processes. To hit the mark on Zero Risk, you also need to mature your cybersecurity model. The Cybersecurity Maturity Model Certification (CMMC) enhances your security practices through five levels of cyber hygiene: Level 1: Basic cyber hygiene: Figure out your current cybersecurity practices and understanding the basics. Level 2: Intermediate cyber hygiene: Document your cybersecurity practices consistency and repeatability. Level 3: Good cyber hygiene: Put proper risk management practices in place to address identified vulnerabilities and threats. Level 4: Proactive cyber hygiene: Routinely and regularly review risks. Continuous monitoring ensures you’re proactive in managing them. Level 5: Advanced and progressive cyber hygiene: Optimize your cybersecurity processes and continuously improving to stay ahead of emerging threats. Focusing on key actions to alignment Aligning Zero Risk with the compliance frameworks involves several key actions: Gap analysis: Conduct a thorough comparison of your current policies, processes, and technologies against the requirements of SOX, GDPR, and the NIST framework. This analysis highlights areas that need improvement and helps prioritize your efforts. Remediation roadmap: Develop a detailed plan (a roadmap of sorts) to address the identified gaps (see the preceding bullet). This plan should prioritize critical areas, allocate resources, and set timelines for completion. Policy communication: Update your policies to align with SOX and GDPR standards, and communicate these changes effectively across your organization. Taking practical measures for compliance To ensure that your Zero Risk strategies are in sync with compliance frameworks, consider the following practical measures: Automating monitoring and reporting: Use identity and application access governance software to automate the monitoring of your systems and the reporting process. This measure not only saves time but also reduces the risk of human error. Regular training: Conduct regular training and awareness programs for employees to ensure that they understand their roles in protecting data and maintaining financial integrity. Continuous monitoring: Implement real-time tracking of all transactions within the application environment. This helps maintain an up-to-date security posture and immediate threat detection. Maintaining compliance and security After you’ve aligned your Zero Risk strategies with compliance frameworks, maintaining that alignment over time is crucial. To stay aligned and ensure ongoing compliance, follow these tips: Perform audits. Conduct regular internal audits to test your financial controls and data security procedures. This action helps identify any compliance drift early on. Stay updated. Keep abreast of changes in compliance frameworks and adjust your policies and procedures accordingly. This means subscribing to regulatory updates, attending relevant seminars and webinars, and participating in industry groups. Regularly revisit your compliance frameworks to ensure they reflect the latest legal and regulatory changes. Document, document, document. Keep an up-to-date record of all data processing activities. This documentation is key to demonstrating compliance during audits. Aligning Zero Risk strategies with cybersecurity and regulatory compliance frameworks is a dynamic process that requires continuous attention and adaptation. By taking a systematic approach to gap analysis, remediation, and ongoing maintenance, organizations can not only enhance their security posture but also ensure they meet the evolving demands of regulatory compliance. This integrated strategy supports sustainable growth and resilience in an increasingly complex digital landscape. Achieving compliance is an accomplishment, but maintaining it is the goal. Falling out of compliance can be costly, so keep reviewing and updating your cybersecurity model to stay ahead of the curve. How Pathlock can help Your organization needs to achieve a Zero Risk application environment, and Pathlock can help. Pathlock’s solutions give you critical tools for planning a proactive defense strategy to continuously monitor and manage risks. To find out more, check out Zero Risk Application Security For Dummies, Pathlock Special Edition. Head to pathlock.com/resource/zero-risk-application-security-for-dummies for your free e-book, and start planning your Zero Risk application security approach.
View ArticleCheat Sheet / Updated 11-13-2024
Drone piloting is for fun . . . and profit, if you want to go that route! It can start out as a hobby and become a side hustle or even a full-time job in a particular industry. From giving you tips about buying a drone, to flying it safely, to taking the Part 107 exam, to cranking up a freelance business, this cheat sheet can help you get your drone piloting goals off the ground.
View Cheat SheetCheat Sheet / Updated 11-13-2024
Whether it’s a desktop the family uses, an office computer, or a liberating laptop you can take with you around the globe, everyone loves to cheat! Specifically, you may find it beneficial to print and save this bonus information to assist you with your beloved computer. Call it helpful hints, but For Dummies tradition labels this document a Cheat Sheet — once a $2.95 value but now free!
View Cheat SheetVideo / Updated 11-13-2024
When you’re new to crafting AI prompts, you can easily make mistakes. Using AI tools the right way makes you more productive and efficient. But if you aren’t careful, you may develop bad habits when you’re still learning. We clue you in to 10 mistakes you should avoid from the start in this video and article. Not Spending Enough Time Crafting and Testing Prompts One common mistake when using AI tools is not putting in the effort to carefully craft your prompts. You may be tempted — very tempted — to quickly type out a prompt and get a response back from the AI, but hurried prompts usually produce mediocre results. Taking the time to compose your prompt using clear language will increase your chances of getting the response you want. A poor response spells the need for you to evaluate the prompt to see where you can clarify or improve it. It’s an iterative process, so don’t be surprised if you have to refine your prompt several times. Like any skill, learning to design effective prompts takes practice and patience. The key is to resist the urge to take shortcuts. Make sure to put in the work needed to guide the AI to a great response. Assuming the AI Understands Context or Subtext It’s easy to overestimate the capabilities of AI tools and assume they understand the meaning of language the way humans do. Current AI tools take things literally. They don’t actually understand the context of a conversation. An AI assistant may be trained to identify patterns and connections and is aware of these things as concepts (like norms, emotions, or sarcasm), all of which rely on context, but it struggles to identify them reliably. Humans can read between the lines and understand meaning beyond what’s actually written. An AI interprets instructions and prompts in a very literal sense — it doesn’t understand the meaning behind them. You can’t assume an AI understands concepts it hasn’t been trained for. Asking Overly Broad or Vague Questions When interacting with an AI, avoid overly broad or vague questions. The AI works best when you give it clear, specific prompts. Providing prompts like “Tell me about human history” or “Explain consciousness” is like asking the AI to search the entire internet. The response will probably be unfocused. The AI has no sense of what information is relevant or important so you need to refocus and try again. Good prompts are more direct. You can start with a prompt such as “Summarize this research paper in two paragraphs” or “Write a 500-word article on summer plants that require shade.” The prompt should give the AI boundaries and context to shape its response. Going from broad to increasingly narrow questions also helps. You can start generally asking about a topic and then follow up with focused requests on the specific details. Providing concrete examples guides the AI. The key is to give the AI precise prompts centered directly on the information you want instead of typing a request with a vague, borderless question. Sharp, specific questioning produces the best AI results. Not Checking Outputs for Errors and Biases A common mistake when using AI apps is taking the results at face value without double-checking them. AI systems may reflect bias, or generate text that seems right but has errors. Just because the content came from an AI doesn’t mean it’s necessarily accurate. Reviewing AI responses rather than blindly trusting the technology is critical. Look for instances of bias where specific demographics are negatively characterized or tropes (clichés) are reinforced. Always check facts and figures against other sources. Look for logic that indicates the AI was “confused.” Providing feedback when the AI makes a mistake can further enhance its training. The key is to approach responses skeptically instead of assuming that the AI always generates perfect results. As with any human team member, reviewing their work is essential before using it. Careful oversight of AI tools mitigates risks. Using Offensive, Unethical, or Dangerous Prompts A primary concern when working with AI is that the apps can inadvertently amplify harmful biases if users write offensive, unethical, or dangerous prompts. The AI will generate text for any input, but the response may be that you’re asking for a harmful response and it will not comply. Prompting an AI with inappropriate language or potential discrimination may reinforce biases from the data the model was trained on. If users are cautious when formulating prompts, that can help steer the technology toward more thoughtful responses. AI can be subject to the whims of bad actors. Expecting Too Much Originality or Creativity from the AI One common mistake when using AI apps is expecting too much original thought or creativity. AI tools can generate unique mixes of text, imagery, and other media, but there are limits. As of this writing, AI apps are only capable of remixing existing information and patterns into new combinations. They can’t really create responses that break new ground. An AI has no natural creative flair like human artists or thinkers. Its training data consists only of past and present works. So, although an AI can generate new work, expecting a “masterpiece” is unrealistic. Copying Generated Content Verbatim A big mistake users make when first using AI tools is to take the text and use it verbatim, without any edits or revisions. AI can often produce text that appears to be well written, but the output is more likely to be a bit rough and require a good edit. Mindlessly copying the unedited output can result in unclear and generic work. (Also, plagiarizing or passing the writing off as your own is unethical.) A best practice is to use the suggestions as a starting point that you build upon with your own words and edits to polish the final product. Keep the strong parts and make it into something original. The key is that the AI app should support your work, not replace it. With the right editing and polishing, you can produce something you’ll be proud of. Providing Too Few Examples and Use Cases When you’re training an AI app to handle a new task, a common mistake is to provide too few examples of inputs. Humans can usually extrapolate from a few samples, but AI apps can’t. An AI must be shown examples to grasp the full scope of the case. You need to feed the AI varied use cases to help it generalize effectively. Similarly, limiting prompts to just a couple of instances produces equally poor results because the AI has little indication of the boundaries of the task. Providing diverse examples helps the AI form an understanding about how to respond. Having patience and supplying many examples lets the AI respond appropriately. Not Customizing Prompts for Different Use Cases One common mistake when working with AI tools is attempting to use the same generic prompt to handle all your use cases. Creating a one-size-fits-all prompt is easier, but it will deliver disappointing results. Each use case and application has its own unique goals and information that need to be conveyed, as discussed throughout this book. For example, a prompt for a creative nonfiction story should be designed differently than a prompt for a medical article. An inventory of prompts designed for various use cases allows the AI to adapt quickly to different needs. The key is customization. Building a library of specialized prompts is an investment that pays dividends. Becoming Overly Reliant on AI Tasks Better Suited for Humans Almost everyone is excited about using AI tools to make their job easier. But it’s important to avoid becoming too dependent on them. AI is great for tasks like automation and personalization, but applying ethics and conveying empathy are still human strengths.
Watch VideoArticle / Updated 11-06-2024
In the ever-accelerating race of data processing and analytics, your organization’s ability to adapt and evolve its data architecture is crucial. As we enter the next data cycle, marked by the rise of artificial intelligence (AI) and deep learning (DL), the demands on data storage and management are unprecedented. This is where hyperscale network-attached storage (NAS) comes into play, offering a transformative solution for organizations looking to capitalize on the next wave of data-driven opportunities. Ushering in the Next Data Cycle with Hyperscale NAS The next data cycle is characterized by a shift from structured business intelligence (BI) data to a world where unstructured and semi-structured data reign supreme. This data is massive in volume and comes from countless sources, which require high-performance access to drive valuable insights. Hyperscale NAS meets this challenge head-on by merging the simplicity of enterprise NAS with the extreme performance of high-performance computing (HPC) parallel file systems. Hyperscale NAS is essential for your organization for the following reasons: Performance at scale: Hyperscale NAS isn’t bottlenecked by traditional NAS controllers, so linear scalability in performance and capacity are enabled across potentially thousands of nodes. Cost efficiency: Being software-defined, hyperscale NAS allows the use of commodity hardware and avoids vendor lock-in, driving down costs significantly. Metadata excellence: With shared metadata kept out of the data path, hyperscale NAS ensures fast access to data across the global environment, which is critical for AI and DL workloads that require rapid data retrieval and processing. Hyperscale NAS: A Pillar for Modern Data Architectures The architecture of hyperscale NAS is fundamentally different from traditional solutions. It overcomes the limitations of scale-out NAS by providing linear scalability and extreme throughput using commodity infrastructure. This means that as your data grows, your system’s performance and capacity can grow with it, without the need for expensive, specialized hardware. Some of the transformative capabilities of hyperscale NAS include Standards-based integration: The hyperscale NAS client software is built into standard Linux distributions, eliminating the need for proprietary clients. Consistent high performance: The separation of metadata from the data path allows for near-full bandwidth utilization, delivering the speed necessary for demanding applications. High availability: Hyperscale NAS includes distributed architecture, load balancing, tiering, and high-availability features, proving itself in some of the world’s largest AI environments. Making Data Available and Actionable In the era of AI, having access to sufficient compute resources, like graphics processing units (GPUs), is a significant challenge. Hyperscale NAS helps you leverage GPUs wherever they’re available, making data a live, globally shared resource that’s no longer localized or trapped within proprietary storage systems or specific cloud data services. Hyperscale NAS makes data more accessible and actionable through Global data sets: Hyperscale NAS orchestrates data to GPUs in the cloud and GPU-as-a-Service providers, unifying multiple data sources into a single global file system. Intelligent data placement: Leveraging metadata-driven data orchestration, Hyperscale NAS ensures data is where it needs to be, when it needs to be there. Non-disruptive data mobility: Data can be moved between storage systems, sites, and clouds without disrupting access or performance. As your organization gears up for the next data cycle, adopting hyperscale NAS isn’t just a strategic move; it’s an imperative one. It’s a future-proof solution that enables you to keep pace with the exponential growth of data and the complex demands of AI and DL. With hyperscale NAS, you can transform your business, unleash the full potential of your data assets, and ensure that your organization isn’t just ready but thriving in the next data cycle. For more information, download this free e-book: Hyperscale NAS For Dummies, Hammerspace Special Edition.
View ArticleArticle / Updated 10-28-2024
The simplest data collection in Python is a list. A list is any list of data items, separated by commas, inside square brackets. Typically, you assign a name to the Python list using an = sign, just as you would with variables. If the list contains numbers, then don't use quotation marks around them. For example, here is a list of test scores: scores = [88, 92, 78, 90, 98, 84] If the list contains strings then, as always, those strings should be enclosed in single or double quotation marks, as in this example: To display the contents of a list on the screen, you can print it just as you would print any regular variable. For example, executing print(students) in your code after defining that list shows this on the screen. ['Mark', 'Amber', 'Todd', 'Anita', 'Sandy'] This may not be exactly what you had in mind. But don’t worry, Python offers lots of great ways to access data in lists and display it however you like. Referencing Python list items by position Each item in a list has a position number, starting with zero, even though you don’t see any numbers. You can refer to any item in the list by its number using the name for the list followed by a number in square brackets. In other words, use this syntax: <em>listname</em>[<em>x</em>] Replace <em><code>listname</code></em> with the name of the list you're accessing and replace <em><code>x</code></em> with the position number of item you want. Remember, the first item is always number zero, not one. For example, in the first line below, I define a list named <code>students</code>, and then print item number zero from that list. The result, when executing the code, is that the name <code>Mark</code> is displayed. students = ["Mark", "Amber", "Todd", "Anita", "Sandy"] print(students[0]) Mark When reading access list items, professionals use the word sub before the number. For example, students[0] would be spoken as students sub zero. This next example shows a list named scores. The print() function prints the position number of the last score in the list, which is 4 (because the first one is always zero). scores = [88, 92, 78, 90, 84] print(scores[4]) 84 If you try to access a list item that doesn't exist, you get an “index out of range” error. The index part is a reference to the number inside the square brackets. For example, the image below shows a little experiment in a Jupyter notebook where a list of scores was created and then the printing of score[5] was attempted. It failed and generated an error because there is no scores[5]. There's only scores[0], scores[1], scores[2], scores[3], and scores[4] because the counting always starts at zero with the first one on the list. Looping through a Python list To access each item in a list, just use a for loop with this syntax: for <em>x</em> in <em>list</em>: Replace >x with a variable name of your choosing. Replace list with the name of the list. An easy way to make the code readable is to always use a plural for the list name (such as students, scores). Then you can use the singular name (student, score) for the variable name. You don't need to use subscript numbers (numbers in square brackets) with this approach either. For example, the following code prints each score in the scores list: for score in scores: print(score) Remember to always indent the code that’s to be executed within the loop. This image shows a more complete example where you can see the result of running the code in a Jupyter notebook. Seeing whether a Python list contains an item If you want your code to check the contents of a list to see whether it already contains some item, use in <em>listname</em> in an if statement or a variable assignment. For example, the code in the image below creates a list of names. Then, two variables store the results of searching the list for the names Anita and Bob. Printing the contents of each variable shows True for the one where the name (Anita) is in the list. The test to see whether Bob is in the list proves False. Getting the length of a Python list To determine how many items are in a list, use the len() function (short for length). Put the name of the list inside the parentheses. For example, type the following code into a Jupyter notebook or Python prompt or whatever: students = ["Mark", "Amber", "Todd", "Anita", "Sandy"] print(len(students)) Running that code produces this output: 5 There are indeed five items in the list, though the last one is always one less than the number because Python starts counting at zero. So the last one, Sandy, actually refers to students[4] and not students[5]. Appending an item to the end of a Python list When you want your Python code to add a new item to the end of a list, use the .append() method with the value you want to add inside the parentheses. You can use either a variable name or a literal value inside the quotation marks. For instance, in the following image the line that reads students.append("Goober") adds the name Goober to the list. The line that reads students.append(new_student) adds whatever name is stored in the variable named new_student to the list. The .append() method always adds to the end of the list. So when you print the list you see those two new names at the end. You can use a test to see whether an item is in a list and then append it only when the item isn't already there. For example, the code below won’t add the name Amber to the list because that name is already in the list: student_name = "Amanda" #Add student_name but only if not already in the list. if student_name in students: print (student_name + " already in the list") else: students.append(student_name) print (student_name + " added to the list") Inserting an item into a Python list Although the append() method allows you to add an item to the end of a list, the insert() method allows you to add an item to the list in any position. The syntax for insert() is <em>listname</em>.insert(<em>position</em>, <em>item</em>) Replace listname with the name of the list, position with the position at which you want to insert the item (for example, 0 to make it the first item, 1 to make it the second item, and so forth). Replace item with the value, or the name of a variable that contains the value, that you want to put into the list. For example, the following code makes Lupe the first item in the list: #Create a list of strings (names). students = ["Mark", "Amber", "Todd", "Anita", "Sandy"] student_name = "Lupe" # Add student name to front of the list. students.insert(0,student_name) #Show me the new list. print(students) If you run the code, print(students) will show the list after the new name has been inserted, as follows: ['Lupe', 'Mark', 'Amber', 'Todd', 'Anita', 'Sandy'] Changing an item in a Python list You can change an item in a list using the = assignment operator (check out these common Python operators) just like you do with variables. Just make sure you include the index number in square brackets of the item you want to change. The syntax is: listname[index]=newvalue Replace listname with the name of the list; replace index with the subscript (index number) of the item you want to change; and replace newvalue with whatever you want to put in the list item. For example, take a look at this code: #Create a list of strings (names). students = ["Mark", "Amber", "Todd", "Anita", "Sandy"] students[3] = "Hobart" print(students) When you run this code, the output is as follows, because Anita's name has been changed to Hobart. ['Mark', 'Amber', 'Todd', 'Hobart', 'Sandy'] Combining Python lists If you have two lists that you want to combine into a single list, use the extend() function with the syntax: <em>original_list</em>.extend(<em>additional_items_list</em>) In your code, replace original_list with the name of the list to which you’ll be adding new list items. Replace additional_items_list with the name of the list that contains the items you want to add to the first list. Here is a simple example using lists named list1 and list2. After executing list1.extend(list2), the first list contains the items from both lists, as you can see in the output of the print() statement at the end. # Create two lists of Names. list1 = ["Zara", "Lupe", "Hong", "Alberto", "Jake"] list2 = ["Huey", "Dewey", "Louie", "Nader", "Bubba"] # Add list2 names to list1. list1.extend(list2) # Print list 1. print(list1) ['Zara', 'Lupe', 'Hong', 'Alberto', 'Jake', 'Huey', 'Dewey', 'Louie', 'Nader', 'Bubba'] Easy Parcheesi, no? Removing Python list items Python offers a remove() method so you can remove any value from the list. If the item is in the list multiple times, only the first occurrence is removed. For example, the following code shows a list of letters with the letter C repeated a few times. Then the code uses letters.remove("C") to remove the letter C from the list: # Remove "C" from the list. letters.remove("C") #Show me the new list. print(letters) When you actually execute this code and then print the list, you'll see that only the first letter C has been removed: ['A', 'B', 'D', 'C', 'E', 'C'] If you need to remove all of an item, you can use a while loop to repeat the .remove as long as the item still remains in the list. For example, this code repeats the .remove as long as the “C” is still in the list. #Create a list of strings. letters = ["A", "B", "C", "D", "C", "E", "C"] If you want to remove an item based on its position in the list, use pop() with an index number rather than remove() with a value. If you want to remove the last item from the list, use pop() without an index number. For example, the following code creates a list, one line removes the first item (0), and another removes the last item (pop() with nothing in the parentheses). Printing the list shows those two items have been removed: #Create a list of strings. letters = ["A", "B", "C", "D", "E", "F", "G"] #Remove the first item. letters.pop(0) #Remove the last item. letters.pop() #Show me the new list. print(letters) Running the code shows that the popping the first and last items did, indeed, work: ['B', 'C', 'D', 'E', 'F'] When you pop() an item off the list, you can store a copy of that value in some variable. For example this image shows the same code as above. However, it stores copies of what's been removed in variables named first_removed and last_removed. At the end it prints the Python list, and also shows which letters were removed. Python also offers a del (short for delete) command that deletes any item from a list based on its index number (position). But again, you have to remember that the first item is zero. So, let's say you run the following code to delete item number 2 from the list: # Create a list of strings. letters = ["A", "B", "C", "D", "E", "F", "G"] # Remove item sub 2. del letters[2] print(letters) Running that code shows the list again, as follows. The letter C has been deleted, which is the correct item to delete because letters are numbered 0, 1, 2, 3, and so forth. ['A', 'B', 'D', 'E', 'F', 'G'] You can also use del to delete an entire list. Just don’t use the square brackets and the index number. For example, the code you see below creates a list then deletes it. Trying to print the list after the deletion causes an error, because the list no longer exists when the print() statement is executed. Clearing out a Python list If you want to delete the contents of a list but not the list itself, use .clear(). The list still exists; however, it contains no items. In other words, it's an empty list. The following code shows how you could test this. Running the code displays [] at the end, which lets you know the list is empty: # Create a list of strings. letters = ["A", "B", "C", "D", "E", "F", "G"] # Clear the list of all entries. letters.clear() # Show me the new list. print(letters) Counting how many times an item appears in a Python list You can use the Python count() method to count how many times an item appears in a list. As with other list methods, the syntax is simple: <em>listname</em>.count(<em>x</em>) Replace listname with the name of your list, and x with the value you're looking for (or the name of a variable that contains that value). The code in the image below counts how many times the letter B appears in the list, using a literal B inside the parentheses of .count(). This same code also counts the number of C grades, but that value was stored in a variable just to show the difference in syntax. Both counts worked, as you can see in the output of the program at the bottom. One was added to count the F's, not using any variables. The F’s were counted right in the code that displays the message. There are no F grades, so this returns zero, as you can see in the output. When trying to combine numbers and strings to form a message, remember you have to convert the numbers to strings using the str() function. Otherwise, you get an error that reads something like can only concatenate str (not "int") to str. In that message, int is short for integer, and str is short for string. Finding a Python list item's index Python offers an .index() method that returns a number indicating the position, based on index number, of an item in a list. The syntax is: <em>listname</em>.index(<em>x</em>) As always, replace listname with name of the list you want to search. Replace x what whatever you're looking for (either as a literal or as a variable name, as always). Of course, there’s no guarantee that the item is in the list, and even if it is, there’s no guarantee that the item is in the list only once. If the item isn’t in the list, then an error occurs. If the item is in the list multiple times, then the index of the first matching item is returned. The following image shows an example where the program crashes at the line f_index = grades.index(look_for) because there is no F in the list. An easy way to get around that problem is to use an if statement to see whether an item is in the list before you try to get its index number. If the item isn't in the list, display a message saying so. Otherwise, get the index number and show it in a message. That code is as follows: # Create a list of strings. grades = ["C", "B", "A", "D", "C", "B", "C"] # Decide what to look for look_for = "F" # See if the item is in the list. if look_for in grades: # If it's in the list, get and show the index. print(str(look_for) + " is at index " + str(grades.index(look_for))) else: # If not in the list, don't even try for index number. print(str(look_for) + " isn't in the list.") Alphabetizing and sorting Python lists Python offers a sort() method for sorting lists. In its simplest form, it alphabetizes the items in the list (if they’re strings). If the list contains numbers, they’re sorted smallest to largest. For a simple sort like that, just use sort() with empty parentheses: <em>listname</em>.sort() Replace listname with the name of your list. The following image shows an example using a list of strings and a list of numbers. In the example, a new list was created for each of them simply by assigning each sorted list to a new list name. Then the code prints the contents of each sorted list. If your list contains strings with a mixture of uppercase and lowercase letters, and if the results of the sort don't look right, try replacing .sort() with .sort(key=lambda s:s.lower()) and then running the code again. Dates are a little trickier because you can’t just type them in as strings, like "12/31/2020". They have to be the date data type to sort correctly. This means using the datetime module and the date() method to define each date. You can add the dates to the list as you would any other list. For example, in the following line, the code creates a list of four dates, and the code is perfectly fine. dates = [dt.date(2020,12,31), dt.date(2019,1,31), dt.date(2018,2,28), dt.date(2020,1,1)] The computer certainly won't mind if you create the list this way. But if you want to make the code more readable to yourself or other developers, you may want to create and append each date, one at a time, so just so it’s a little easier to see what’s going on and so you don’t have to deal with so many commas in one line of code. The image below shows an example where an empty list named datelist was created: datelist = [] Then one date at a time was appended to the list using the dt.date(<em>year</em>,<em>month</em>,<em>day</em>) syntax. After the list is created, the code uses datelist.sort() to sort them into chronological order (earliest to latest). You don’t need to use print(datelist) in that code because that method displays the dates with the data type information included, like this: [datetime.date(2018, 2, 28), datetime.date(2019, 1, 31), datetime.date (2020, 1, 1), datetime.date(2020, 12, 31)] Not the easiest list to read. So, rather than print the whole list with one print() statement, you can loop through each date in the list, and printed each one formatted with the f-string %m/%d/%Y. This displays each date on its own line in mm/dd/yyyy format, as you can see at the bottom of the image above. If you want to sort items in reverse order, put reverse=True inside the sort() parentheses (and don't forget to make the first letter uppercase). The image below shows examples of sorting all three lists in descending (reverse) order using reverse=True. Reversing a Python list You can also reverse the order of items in a list using the .reverse method. This is not the same as sorting in reverse, because when you sort in reverse, you still actually sort: Z–A for strings, largest to smallest for numbers, latest to earliest for dates. When you reverse a list, you simply reverse the items in the list, no matter their order, without trying to sort them in any way. The following code shows an example in which you reverse the order of the names in the list and then print the list. The output shows the list items reversed from their original order: # Create a list of strings. names = ["Zara", "Lupe", "Hong", "Alberto", "Jake"] # Reverse the list names.reverse() # Print the list print(names) ['Jake', 'Alberto', 'Hong', 'Lupe', 'Zara'] Copying a Python list If you ever need to work with a copy of a list, use the .copy() method so as not to alter the original list,. For example, the following code is similar to the preceding code, except that instead of reversing the order of the original list, you make a copy of the list and reverse that one. Printing the contents of each list shows how the first list is still in the original order whereas the second one is reversed: # Create a list of strings. names = ["Zara", "Lupe", "Hong", "Alberto", "Jake"] # Make a copy of the list backward_names = names.copy() # Reverse the copy backward_names.reverse() # Print the list print(names) print(backward_names) ['Zara', 'Lupe', 'Hong', 'Alberto', 'Jake'] ['Jake', 'Alberto', 'Hong', 'Lupe', 'Zara'] For future references, the following table summarizes the methods you've learned about. Methods for Working with Lists Method What it Does append() Adds an item to the end of the list. clear() Removes all items from the list, leaving it empty. copy() Makes a copy of a list. count() Counts how many times an element appears in a list. extend() Appends the items from one list to the end of another list. index() Returns the index number (position) of an element within a list. insert() Inserts an item into the list at a specific position. pop() Removes an element from the list, and provides a copy of that item that you can store in a variable. remove() Removes one item from the list. reverse() Reverses the order of items in the list. sort() Sorts the list in ascending order. Put reverse=True inside the parentheses to sort in descending order.
View ArticleArticle / Updated 10-28-2024
Bayes’ theorem can help you deduce how likely something is to happen in a certain context, based on the general probabilities of the fact itself and the evidence you examine, and combined with the probability of the evidence given the fact. Seldom will a single piece of evidence diminish doubts and provide enough certainty in a prediction to ensure that it will happen. As a true detective, to reach certainty, you have to collect more evidence and make the individual pieces work together in your investigation. Noticing that a person has long hair isn’t enough to determine whether person is female or a male. Adding data about height and weight could help increase confidence. The Naïve Bayes algorithm helps you arrange all the evidence you gather and reach a more solid prediction with a higher likelihood of being correct. Gathered evidence considered singularly couldn’t save you from the risk of predicting incorrectly, but all evidence summed together can reach a more definitive resolution. The following example shows how things work in a Naïve Bayes classification. This is an old, renowned problem, but it represents the kind of capability that you can expect from an AI. The dataset is from the paper “Induction of Decision Trees,” by John Ross Quinlan. Quinlan is a computer scientist who contributed to the development of another machine learning algorithm, decision trees, in a fundamental way, but his example works well with any kind of learning algorithm. The problem requires that the AI guess the best conditions to play tennis given the weather conditions. The set of features described by Quinlan is as follows: Outlook: Sunny, overcast, or rainy Temperature: Cool, mild, or hot Humidity: High or normal Windy: True or false The following table contains the database entries used for the example: Outlook Temperature Humidity Windy PlayTennis Sunny Hot High False No Sunny Hot High True No Overcast Hot High False Yes Rainy Mild High False Yes Rainy Cool Normal False Yes Rainy Cool Normal True No Overcast Cool Normal True Yes Sunny Mild High False No Sunny Cool Normal False Yes Rainy Mild Normal False Yes Sunny Mild Normal True Yes Overcast Mild High True Yes Overcast Hot Normal False Yes Rainy Mild High True No The option of playing tennis depends on the four arguments shown here. The result of this AI learning example is a decision as to whether to play tennis, given the weather conditions (the evidence). Using just the outlook (sunny, overcast, or rainy) won’t be enough, because the temperature and humidity could be too high or the wind might be strong. These arguments represent real conditions that have multiple causes, or causes that are interconnected. The Naïve Bayes algorithm is skilled at guessing correctly when multiple causes exist. The algorithm computes a score, based on the probability of making a particular decision and multiplied by the probabilities of the evidence connected to that decision. For instance, to determine whether to play tennis when the outlook is sunny but the wind is strong, the algorithm computes the score for a positive answer by multiplying the general probability of playing (9 played games out of 14 occurrences) by the probability of the day’s being sunny (2 out of 9 played games) and of having windy conditions when playing tennis (3 out of 9 played games). The same rules apply for the negative case (which has different probabilities for not playing given certain conditions): likelihood of playing: 9/14 * 2/9 * 3/9 = 0.05 likelihood of not playing: 5/14 * 3/5 * 3/5 = 0.13 Because the score for the likelihood is higher, the algorithm decides that it’s safer not to play under such conditions. It computes such likelihood by summing the two scores and dividing both scores by their sum: probability of playing : 0.05 / (0.05 + 0.13) = 0.278 probability of not playing : 0.13 / (0.05 + 0.13) = 0.722 You can further extend Naïve Bayes to represent relationships that are more complex than a series of factors that hint at the likelihood of an outcome using a Bayesian network, which consists of graphs showing how events affect each other. Bayesian graphs have nodes that represent the events and arcs showing which events affect others, accompanied by a table of conditional probabilities that show how the relationship works in terms of probability. The figure shows a famous example of a Bayesian network taken from a 1988 academic paper, “Local computations with probabilities on graphical structures and their application to expert systems,” by Lauritzen, Steffen L. and David J. Spiegelhalter, published by the Journal of the Royal Statistical Society. The depicted network is called Asia. It shows possible patient conditions and what causes what. For instance, if a patient has dyspnea, it could be an effect of tuberculosis, lung cancer, or bronchitis. Knowing whether the patient smokes, has been to Asia, or has anomalous x-ray results (thus giving certainty to certain pieces of evidence, a priori in Bayesian language) helps infer the real (posterior) probabilities of having any of the pathologies in the graph. Bayesian networks, though intuitive, have complex math behind them, and they’re more powerful than a simple Naïve Bayes algorithm because they mimic the world as a sequence of causes and effects based on probability. Bayesian networks are so effective that you can use them to represent any situation. They have varied applications, such as medical diagnoses, the fusing of uncertain data arriving from multiple sensors, economic modeling, and the monitoring of complex systems such as a car. For instance, because driving in highway traffic may involve complex situations with many vehicles, the Analysis of MassIve Data STreams (AMIDST) consortium, in collaboration with the automaker Daimler, devised a Bayesian network that can recognize maneuvers by other vehicles and increase driving safety.
View ArticleArticle / Updated 10-28-2024
YouTube is a video-sharing website where users post all kinds of media. YouTube is so popular that it has one billion unique visits every single month. From how-tos to educational cartoons, YouTube has a large selection of videos from every genre. You’ve likely watched videos on YouTube and seen something that you might want to watch when you don’t have access to the internet. Need a cartoon for your child who watch while on an airplane? Or, maybe an instructional video to review while actually doing the task later? Downloading YouTube videos is quite simple. How to download YouTube videos with Keepvid You can use keepvid.com to download YouTube videos. Follow these steps to use Keepvid: Go to YouTube and find the video you’d like to download. Click the Share button underneath the video on YouTube to copy the link. Open a new window and navigate to keepvid.com. Paste the link into the download text box. Click download and save the video.All done! Keepvid can also download videos from other websites, including videos posted to social media. Before you begin downloading videos from YouTube, you need to understand the legal issues that accompany your use of those videos. YouTube content is copyrighted. That means that you absolutely cannot download it for anything other than personal use. Also, Google (the owner of YouTube) includes terms of service for users. These terms specifically state: “You shall not download any Content unless you see a 'download' or similar link displayed by YouTube on the Service for that Content” (Section 5 – B). The following is provided for informational purposes only. There are several methods for downloading YouTube videos. The instructions above discuss one popular way to complete the task, but other options exist. There are numerous software suites available to download these videos. If you prefer this method, you can easily find choices by searching the internet for “YouTube downloading software.” The directions you find here discuss the use of websites that are specifically created to download YouTube videos.
View ArticleArticle / Updated 10-28-2024
The words int and double are examples of primitive types (also known as simple types) in Java. The Java language has exactly eight primitive types. As a newcomer to Java, you can pretty much ignore all but four of these types. (As programming languages go, Java is nice and compact that way.) The types that you shouldn’t ignore are int, double, char, and boolean. The char type Several decades ago, people thought computers existed only for doing big number-crunching calculations. Nowadays, nobody thinks that way. So, if you haven’t been in a cryogenic freezing chamber for the past 20 years, you know that computers store letters, punctuation symbols, and other characters. The Java type that’s used to store characters is called char. The code below has a simple program that uses the char type. This image shows the output of the program in the code below. public class CharDemo { public static void main(String args[]) { char myLittleChar = 'b'; char myBigChar = Character.toUpperCase(myLittleChar); System.out.println(myBigChar); } } In this code, the first initialization stores the letter b in the variable myLittleChar. In the initialization, notice how b is surrounded by single quote marks. In Java, every char literally starts and ends with a single quote mark. In a Java program, single quote marks surround the letter in a char literal. Character.toUpperCase. The Character.toUpperCase method does just what its name suggests — the method produces the uppercase equivalent of the letter b. This uppercase equivalent (the letter B) is assigned to the myBigChar variable, and the B that’s in myBigChar prints onscreen. If you’re tempted to write the following statement, char myLittleChars = 'barry'; //Don't do this please resist the temptation. You can’t store more than one letter at a time in a char variable, and you can’t put more than one letter between a pair of single quotes. If you’re trying to store words or sentences (not just single letters), you need to use something called a String. If you’re used to writing programs in other languages, you may be aware of something called ASCII character encoding. Most languages use ASCII; Java uses Unicode. In the old ASCII representation, each character takes up only 8 bits, but in Unicode, each character takes up 8, 16, or 32 bits. Whereas ASCII stores the letters of the Roman (English) alphabet, Unicode has room for characters from most of the world’s commonly spoken languages. The only problem is that some of the Java API methods are geared specially toward 16-bit Unicode. Occasionally, this bites you in the back (or it bytes you in the back, as the case may be). If you’re using a method to write Hello on the screen and H e l l o shows up instead, check the method’s documentation for mention of Unicode characters. It’s worth noticing that the two methods, Character.toUpperCase and System.out.println, are used quite differently in the code above. The method Character.toUpperCase is called as part of an initialization or an assignment statement, but the method System.out.println is called on its own. The boolean type A variable of type boolean stores one of two values: true or false. The code below demonstrates the use of a boolean variable. public class ElevatorFitter2 { public static void main(String args[]) { System.out.println("True or False?"); System.out.println("You can fit all ten of the"); System.out.println("Brickenchicker dectuplets"); System.out.println("on the elevator:"); System.out.println(); int weightOfAPerson = 150; int elevatorWeightLimit = 1400; int numberOfPeople = elevatorWeightLimit / weightOfAPerson; <strong> boolean allTenOkay = numberOfPeople >= 10;</strong> System.out.println(allTenOkay); } } In this code, the allTenOkay variable is of type boolean. To find a value for the allTenOkay variable, the program checks to see whether numberOfPeople is greater than or equal to ten. (The symbols >= stand for greater than or equal to.) At this point, it pays to be fussy about terminology. Any part of a Java program that has a value is an expression. If you write weightOfAPerson = 150; then 150 ,is an expression (an expression whose value is the quantity 150). If you write numberOfEggs = 2 + 2; then 2 + 2 is an expression (because 2 + 2 has the value 4). If you write int numberOfPeople = elevatorWeightLimit / weightOfAPerson; then elevatorWeightLimit / weightOfAPerson is an expression. (The value of the expression elevatorWeightLimit / weightOfAPerson depends on whatever values the variables elevatorWeightLimit and weightOfAPerson have when the code containing the expression is executed.) Any part of a Java program that has a value is an expression. In the second set of code, numberOfPeople >= 10 is an expression. The expression’s value depends on the value stored in the numberOfPeople variable. But, as you know from seeing the strawberry shortcake at the Brickenchicker family’s catered lunch, the value of numberOfPeople isn’t greater than or equal to ten. As a result, the value of numberOfPeople >= 10 is false. So, in the statement in the second set of code, in which allTenOkay is assigned a value, the allTenOkay variable is assigned a false value. In the second set of code, System.out.println() is called with nothing inside the parentheses. When you do this, Java adds a line break to the program’s output. In the second set of code, System.out.println() tells the program to display a blank line.
View Article