Sunday, 26 November 2023

10 BOOKS THAT WILL BOOST YOUR PRODUCTIVITY!

 













10 BOOKS THAT WILL BOOST YOUR PRODUCTIVITY!

1. Focus on What Matters: A Collection of Stoic Letters on Living Well https://amzn.to/3RgjAJe

2. How to Finish Everything You Start https://amzn.to/3N1KtOr

3. Do It Today: Overcome Procrastination, Improve Productivity, and Achieve More Meaningful Things https://amzn.to/3uDL9mK

4. Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones https://amzn.to/49UM3vy

5. Deep Work: Rules for Focused Success in a Distracted World https://amzn.to/3T0lPSo

6. Attention Span: Finding Focus for a Fulfilling Life https://amzn.to/3uv1Lgx


8. Do Epic Shit https://amzn.to/3QZfaFc

9. Do the Hard Things First: How to Win Over Procrastination and Master the Habit of Doing Difficult Work (Bulletproof Mindset Mastery Series https://amzn.to/47Nry1Z

10. Do the Impossible: How to Become Extraordinary and Impact the World at Scale (Becoming Extraordinary, Book 1) https://amzn.to/3Ghgrm7

Match the following for the each values !!

 


Answer

tpl1 = ('A',) - Tuple

tpl1 = ('A') - String

t = tpl[::-1] - Sorts tuple

('A', 'B', 'C', 'D') - tuple of strings

[(1, 2), (2, 3), (4, 5)] - list of tuples

tpl = tuple(range(2, 5)) - (2, 3, 4)

([1, 2], [3, 4], [5, 6]) - tuple of lists

t = tuple('Ajooba') - tuple of length 6


Explanation: 

tpl1 = ('A',) - This creates a tuple named tpl1 containing a single element 'A'. Note the comma after 'A', which is essential for creating a tuple with a single element.


tpl1 = ('A') - This actually creates a string, not a tuple. To create a tuple with a single element, you need to include a comma: tpl1 = ('A',).


t = tpl[::-1] - This reverses the order of elements in the tuple tpl. The [::-1] slicing notation is used to reverse the sequence.


('A', 'B', 'C', 'D') - This is a tuple of strings with four elements: 'A', 'B', 'C', and 'D'.


[(1, 2), (2, 3), (4, 5)] - This is a list of tuples, where each tuple contains two integers.


tpl = tuple(range(2, 5)) - This creates a tuple named tpl with elements generated using range(2, 5), resulting in the tuple (2, 3, 4).


([1, 2], [3, 4], [5, 6]) - This is a tuple of lists, where each list contains two integers.


t = tuple('Ajooba') - This creates a tuple named t from the characters of the string 'Ajooba'. The resulting tuple has six elements, one for each character.

Saturday, 25 November 2023

Python Programming for Data Analysis (Free PDF)

 


This textbook grew out of notes for the ECE143 Programming for Data Analysis class that the author has been teaching at University of California, San Diego, which is a requirement for both graduate and undergraduate degrees in Machine Learning and Data Science. This book is ideal for readers with some Python programming experience. The book covers key language concepts that must be understood to program effectively, especially for data analysis applications. Certain low-level language features are discussed in detail, especially Python memory management and data structures. Using Python effectively means taking advantage of its vast ecosystem. The book discusses Python package management and how to use third-party modules as well as how to structure your own Python modules.  The section on object-oriented programming explains features of the language that facilitate common programming patterns.

After developing the key Python language features, the book moves on to third-party modules that are foundational for effective data analysis, starting with Numpy. The book develops key Numpy concepts and discusses internal Numpy array data structures and memory usage. Then, the author moves onto Pandas and details its many features for data processing and alignment. Because strong visualizations are important for communicating data analysis, key modules such as Matplotlib are developed in detail, along with web-based options such as Bokeh, Holoviews, Altair, and Plotly.


The text is sprinkled with many tricks-of-the-trade that help avoid common pitfalls. The author explains the internal logic embodied in the Python language so that readers can get into the Python mindset and make better design choices in their codes, which is especially helpful for newcomers to both Python and data analysis. 

To get the most out of this book, open a Python interpreter and type along with the many code samples.

Buy : Python Programming for Data Analysis 

PDF Download : 


Python Coding challenge - Day 77 | What is the output of the following Python code?

 

Code : 


def fun(a, *args, s='!'):
    print(a, s)
    for i in args:
        print(i, s)

fun(10)

Solution and Explanation: 

Function Definition:

def fun(a, *args, s='!'):

The function fun is defined to take at least one argument a, followed by any number of additional positional arguments (*args), and an optional keyword argument s with a default value of '!'.


Print the First Argument and Suffix:

print(a, s)

This line prints the value of the first argument a followed by the value of the keyword argument s.


Loop through Additional Arguments:

for i in args:

    print(i, s)

This loop iterates through any additional positional arguments provided (if any) and prints each one followed by the value of the keyword argument s.


Function Call:

fun(10)

The function is called with the argument 10. Since no additional positional arguments are provided, only the first print statement is executed.


When you run this code, it will output:

10 !

What will be the output of the following Python code ?

Code : 

s = [a + b for a in ['They ', 'We '] for b in ['are gone!', 'have come!']]

print(s)


Solution and Explanation :  

This code uses list comprehension to create a list s by concatenating elements from two nested lists. Here's the breakdown:

s = [a + b for a in ['They ', 'We '] for b in ['are gone!', 'have come!']]

Two nested for loops are used in the list comprehension.

The outer loop iterates over elements a in the list ['They ', 'We '].

The inner loop iterates over elements b in the list ['are gone!', 'have come!'].

The expression a + b concatenates the current elements from both loops.

The result is a new list s containing all possible concatenations of elements from the outer and inner loops.

If you print the list s, you will get:

['They are gone!', 'They have come!', 'We are gone!', 'We have come!']

This is because it combines each element from the first list with each element from the second list, resulting in all possible combinations.

a = set() for n in range(21, 30): if n % 2 == 0: a.add(n) print(a)

 Code : 

a = set()

for n in range(21, 30):

    if n % 2 == 0:

        a.add(n)

print(a)

Solution and Explanation:

Let's break down the code step by step:

Initialize an empty set:

a = set()

A new empty set named a is created.

Loop through a range of numbers (21 to 29):

for n in range(21, 30):

The for loop iterates over the numbers from 21 to 29 (inclusive).

Check if the number is even:

if n % 2 == 0:

The if statement checks if the current number (n) is even by using the modulo operator (%) to check if it's divisible by 2.


Add even numbers to the set:

a.add(n)

If the condition in the if statement is true (meaning n is even), the current even number is added to the set a using the add method.


Print the set after the loop:

print(a)

The print(a) statement is outside the for loop, so it will be executed after the loop has finished. It prints the final contents of the set a.

In summary, when you run this code, it will output the set of even numbers between 21 and 29. In this specific case, the set a will contain the even numbers 22, 24, 26, and 28.


In one line : a = {n for n in range(21, 30) if n % 2 == 0}






State whether the following statements are True or False in Python

 



a. Tuple comprehension offers a fast and compact way to generate a tuple.

Answer

True

b. List comprehension and dictionary comprehension can be nested.

Answer

True

c. A list being used in a list comprehension cannot be modified when it is

being iterated.

Answer

True

d. Sets being immutable cannot be used in comprehension.

Answer

False

e. Comprehensions can be used to create a list, set or a dictionary.

Answer

True

Introduction to Artificial Intelligence (AI)

 


What you'll learn

Describe what is AI, its applications, use cases, and how it is transforming our lives

Explain terms like Machine Learning, Deep Learning and Neural Networks 

Describe several issues and ethical concerns surrounding AI

Articulate advice from experts about learning and starting a career in AI 

There are 4 modules in this course

In this course you will learn what Artificial Intelligence (AI) is, explore use cases and applications of AI, understand AI concepts and terms like machine learning, deep learning and neural networks. You will be exposed to various issues and concerns surrounding AI such as ethics and bias, & jobs, and get advice from experts about learning and starting a career in AI.  You will also demonstrate AI in action with a mini project.

This course does not require any programming or computer science expertise and is designed to introduce the basics of AI to anyone whether you have a technical background or not. 

Join Free  - Introduction to Artificial Intelligence (AI)

a = 10 if a in (30, 40, 50): print('Hello') else: print('Hi')

 Code : 

a = 10

if a in (30, 40, 50):

    print('Hello')

else:

    print('Hi')

Solution and Explanation : 

In this example, the value of a is 10, and it's being checked if it's present in the tuple (30, 40, 50). Since 10 is not in that tuple, the else block will be executed, and 'Hi' will be printed. So, when you run this code, you should see the output: Hi

Let's go through the code step by step:

a = 10
Here, a variable a is assigned the value 10.

if a in (30, 40, 50):
This line checks if the value of a is present in the tuple (30, 40, 50). In this case, since a is 10 and 10 is not in the tuple, the condition is False.

    print('Hello')
Since the condition in the if statement is False, the code inside the if block is skipped, and this line is not executed.

else:
Because the condition in the if statement is False, the code inside the else block will be executed.

    print('Hi')
This line prints 'Hi' to the console because the code is now in the else block.

So, when you run this code, the output will be:

Hi

This is because the value of a (which is 10) is not in the specified tuple (30, 40, 50).

Process Mining: Data science in Action (Free Course)

 


There are 6 modules in this course

Process mining is the missing link between model-based process analysis and data-oriented analysis techniques. Through concrete data sets and easy to use software the course provides data science knowledge that can be applied directly to analyze and improve processes in a variety of domains.


Data science is the profession of the future, because organizations that are unable to use (big) data in a smart way will not survive. It is not sufficient to focus on data storage and data analysis. The data scientist also needs to relate data to process analysis. Process mining bridges the gap between traditional model-based process analysis (e.g., simulation and other business process management techniques) and data-centric analysis techniques such as machine learning and data mining. Process mining seeks the confrontation between event data (i.e., observed behavior) and process models (hand-made or discovered automatically). This technology has become available only recently, but it can be applied to any type of operational processes (organizations and systems). Example applications include: analyzing treatment processes in hospitals, improving customer service processes in a multinational, understanding the browsing behavior of customers using booking site, analyzing failures of a baggage handling system, and improving the user interface of an X-ray machine. All of these applications have in common that dynamic behavior needs to be related to process models. Hence, we refer to this as "data science in action".


The course explains the key analysis techniques in process mining. Participants will learn various process discovery algorithms. These can be used to automatically learn process models from raw event data. Various other process analysis techniques that use event data will be presented. Moreover, the course will provide easy-to-use software, real-life data sets, and practical skills to directly apply the theory in a variety of application domains.


This course starts with an overview of approaches and technologies that use event data to support decision making and business process (re)design. Then the course focuses on process mining as a bridge between data mining and business process modeling. The course is at an introductory level with various practical assignments.


The course covers the three main types of process mining.


1. The first type of process mining is discovery. A discovery technique takes an event log and produces a process model without using any a-priori information. An example is the Alpha-algorithm that takes an event log and produces a process model (a Petri net) explaining the behavior recorded in the log.


2. The second type of process mining is conformance. Here, an existing process model is compared with an event log of the same process. Conformance checking can be used to check if reality, as recorded in the log, conforms to the model and vice versa.


3. The third type of process mining is enhancement. Here, the idea is to extend or improve an existing process model using information about the actual process recorded in some event log. Whereas conformance checking measures the alignment between model and reality, this third type of process mining aims at changing or extending the a-priori model. An example is the extension of a process model with performance information, e.g., showing bottlenecks. Process mining techniques can be used in an offline, but also online setting. The latter is known as operational support. An example is the detection of non-conformance at the moment the deviation actually takes place. Another example is time prediction for running cases, i.e., given a partially executed case the remaining processing time is estimated based on historic information of similar cases.


Process mining provides not only a bridge between data mining and business process management; it also helps to address the classical divide between "business" and "IT". Evidence-based business process management based on process mining helps to create a common ground for business process improvement and information systems development.


The course uses many examples using real-life event logs to illustrate the concepts and algorithms. After taking this course, one is able to run process mining projects and have a good understanding of the Business Process Intelligence field.


After taking this course you should:

- have a good understanding of Business Process Intelligence techniques (in particular process mining),

- understand the role of Big Data in today’s society,

- be able to relate process mining techniques to other analysis techniques such as simulation, business intelligence, data mining, machine learning, and verification,

- be able to apply basic process discovery techniques to learn a process model from an event log (both manually and using tools),

- be able to apply basic conformance checking techniques to compare event logs and process models (both manually and using tools),

- be able to extend a process model with information extracted from the event log (e.g., show bottlenecks),

- have a good understanding of the data needed to start a process mining project,

- be able to characterize the questions that can be answered based on such event data,

- explain how process mining can also be used for operational support (prediction and recommendation), and

- be able to conduct process mining projects in a structured manner.


Join Free - Process Mining: Data science in Action



Introduction to Mathematical Thinking (Free Course)

 


There are 9 modules in this course

Learn how to think the way mathematicians do – a powerful cognitive process developed over thousands of years.

Mathematical thinking is not the same as doing mathematics – at least not as mathematics is typically presented in our school system. School math typically focuses on learning procedures to solve highly stereotyped problems. Professional mathematicians think a certain way to solve real problems, problems that can arise from the everyday world, or from science, or from within mathematics itself. The key to success in school math is to learn to think inside-the-box. In contrast, a key feature of mathematical thinking is thinking outside-the-box – a valuable ability in today’s world. This course helps to develop that crucial way of thinking.

Join Free  - Introduction to Mathematical Thinking

Python Coding challenge - Day 76 | What is the output of the following Python code?

 

Code : 

def f1(a,b=[]):

  b.append(a)

  return b

print (f1(2,[3,4]))


Solution and Explanation: 

Answer : [3, 4, 2]

In the given code, you have a function f1 that takes two parameters a and b, with a default value of an empty list [] for b. The function appends the value of a to the list b and then returns the modified list.

When you call f1(2, [3, 4]), it means you are passing the value 2 for a and the list [3, 4] for b. The function then appends 2 to the provided list, and the modified list [3, 4, 2] is returned.

However, it's important to note that when you use a mutable default argument like a list (b=[]), it can lead to unexpected behavior. The default value is created only once when the function is defined, not each time the function is called. So, if you modify the default list (e.g., by appending elements to it), the changes persist across multiple function calls.

If you were to call the function again without providing a value for b, it would continue to use the modified list from the previous call. Here's an example:

print(f1(3))  # Output: [3]

The default value for b is now [3] because of the previous call.

To avoid this issue, it's generally recommended to use None as the default value and create a new list inside the function if needed. Here's an updated version of your function:

def f1(a, b=None):
    if b is None:
        b = []
    b.append(a)
    return b

print(f1(2, [3, 4]))
print(f1(3))
This way, you ensure that a new list is created for each call when a value for b is not provided.

Dive into Deep Learning (Free PDF)

 


Deep learning has revolutionized pattern recognition, introducing tools that power a wide range of technologies in such diverse fields as computer vision, natural language processing, and automatic speech recognition. Applying deep learning requires you to simultaneously understand how to cast a problem, the basic mathematics of modeling, the algorithms for fitting your models to data, and the engineering techniques to implement it all. This book is a comprehensive resource that makes deep learning approachable, while still providing sufficient technical depth to enable engineers, scientists, and students to use deep learning in their own work. No previous background in machine learning or deep learning is required―every concept is explained from scratch and the appendix provides a refresher on the mathematics needed. Runnable code is featured throughout, allowing you to develop your own intuition by putting key ideas into practice.

Buy : Dive into Deep Learning

Friday, 24 November 2023

Mathematics for Machine Learning Specialization

 


Specialization - 3 course series

For a lot of higher level courses in Machine Learning and Data Science, you find you need to freshen up on the basics in mathematics - stuff you may have studied before in school or university, but which was taught in another context, or not very intuitively, such that you struggle to relate it to how it’s used in Computer Science. This specialization aims to bridge that gap, getting you up to speed in the underlying mathematics, building an intuitive understanding, and relating it to Machine Learning and Data Science.

In the first course on Linear Algebra we look at what linear algebra is and how it relates to data. Then we look through what vectors and matrices are and how to work with them.

The second course, Multivariate Calculus, builds on this to look at how to optimize fitting functions to get good fits to data. It starts from introductory calculus and then uses the matrices and vectors from the first course to look at data fitting.

The third course, Dimensionality Reduction with Principal Component Analysis, uses the mathematics from the first two courses to compress high-dimensional data. This course is of intermediate difficulty and will require Python and numpy knowledge.

At the end of this specialization you will have gained the prerequisite mathematical knowledge to continue your journey and take more advanced courses in machine learning.

Applied Learning Project

Through the assignments of this specialisation you will use the skills you have learned to produce mini-projects with Python on interactive notebooks, an easy to learn tool which will help you apply the knowledge to real world problems. For example, using linear algebra in order to calculate the page rank of a small simulated internet, applying multivariate calculus in order to train your own neural network, performing a non-linear least squares regression to fit a model to a data set, and using principal component analysis to determine the features of the MNIST digits data set.

Join Free : Mathematics for Machine Learning Specialization

Mathematics for Machine Learning (Free PDF)

 


The fundamental mathematical tools needed to understand machine learning include linear algebra, analytic geometry, matrix decompositions, vector calculus, optimization, probability and statistics. These topics are traditionally taught in disparate courses, making it hard for data science or computer science students, or professionals, to efficiently learn the mathematics. This self contained textbook bridges the gap between mathematical and machine learning texts, introducing the mathematical concepts with a minimum of prerequisites. It uses these concepts to derive four central machine learning methods: linear regression, principal component analysis, Gaussian mixture models and support vector machines. For students and others with a mathematical background, these derivations provide a starting point to machine learning texts. For those learning the mathematics for the first time, the methods help build intuition and practical experience with applying mathematical concepts. Every chapter includes worked examples and exercises to test understanding. Programming tutorials are offered on the book's web site.

Buy : Mathematics for Machine Learning


PDF Downloads: Mathematics for Machine Learning

Probabilistic Machine Learning: An Introduction (Adaptive Computation and Machine Learning series) (Free PDF)

 


A detailed and up-to-date introduction to machine learning, presented through the unifying lens of probabilistic modeling and Bayesian decision theory.

This book offers a detailed and up-to-date introduction to machine learning (including deep learning) through the unifying lens of probabilistic modeling and Bayesian decision theory. The book covers mathematical background (including linear algebra and optimization), basic supervised learning (including linear and logistic regression and deep neural networks), as well as more advanced topics (including transfer learning and unsupervised learning). End-of-chapter exercises allow students to apply what they have learned, and an appendix covers notation.

Probabilistic Machine Learning grew out of the author’s 2012 book, Machine Learning: A Probabilistic Perspective. More than just a simple update, this is a completely new book that reflects the dramatic developments in the field since 2012, most notably deep learning. In addition, the new book is accompanied by online Python code, using libraries such as scikit-learn, JAX, PyTorch, and Tensorflow, which can be used to reproduce nearly all the figures; this code can be run inside a web browser using cloud-based notebooks, and provides a practical complement to the theoretical topics discussed in the book. This introductory text will be followed by a sequel that covers more advanced topics, taking the same probabilistic approach.

Buy : Probabilistic Machine Learning: An Introduction (Adaptive Computation and Machine Learning series)


Download : Probabilistic Machine Learning: An Introduction (Adaptive Computation and Machine Learning series)

Foundations of Data Science (Free PDF)


This book provides an introduction to the mathematical and algorithmic foundations of data science, including machine learning, high-dimensional geometry, and analysis of large networks. Topics include the counterintuitive nature of data in high dimensions, important linear algebraic techniques such as singular value decomposition, the theory of random walks and Markov chains, the fundamentals of and important algorithms for machine learning, algorithms and analysis for clustering, probabilistic models for large networks, representation learning including topic modelling and non-negative matrix factorization, wavelets and compressed sensing. Important probabilistic techniques are developed including the law of large numbers, tail inequalities, analysis of random projections, generalization guarantees in machine learning, and moment methods for analysis of phase transitions in large random graphs. Additionally, important structural and complexity measures are discussed such as matrix norms and VC-dimension. This book is suitable for both undergraduate and graduate courses in the design and analysis of algorithms for data.

Buy : Foundations of Data Science


Download: Foundations of Data Science

Book Description

Covers mathematical and algorithmic foundations of data science: machine learning, high-dimensional geometry, and analysis of large networks.

About the Author

Avrim Blum is Chief Academic Officer at Toyota Technical Institute at Chicago and formerly Professor at Carnegie Mellon University, Pennsylvania. He has over 25,000 citations for his work in algorithms and machine learning. He has received the AI Journal Classic Paper Award, ICML/COLT 10-Year Best Paper Award, Sloan Fellowship, NSF NYI award, and Herb Simon Teaching Award, and is a Fellow of the Association for Computing Machinery (ACM).

John Hopcroft is a member of the National Academy of Sciences and National Academy of Engineering, and a foreign member of the Chinese Academy of Sciences. He received the Turing Award in 1986, was appointed to the National Science Board in 1992 by President George H. W. Bush, and was presented with the Friendship Award by Premier Li Keqiang for his work in China.

Ravi Kannan is Principal Researcher for Microsoft Research, India. He was the recipient of the Fulkerson Prize in Discrete Mathematics (1991) and the Knuth Prize (ACM) in 2011. He is a distinguished alumnus of the Indian Institute of Technology, Bombay, and his past faculty appointments include Massachusetts Institute of Technology, Carnegie Mellon University, Pennsylvania, Yale University, Connecticut, and the Indian Institute of Science.

a = 10 if a = 30 or 40 or 60 : print('Hello') else : print('Hi')

Code :

a = 10

if a = 30 or 40 or 60 :

print('Hello')

else :

print('Hi')


Solution and Explanation:

Answer : Error

The equality comparison should use == instead of =. Second, you need to compare the variable a against each value separately. Here's the corrected version:

a = 10
if a == 30 or a == 40 or a == 60:
    print('Hello')
else:
    print('Hi')

This way, it checks if a is equal to any of the specified values (30, 40, or 60) and prints 'Hello' if true, otherwise, it prints 'Hi'.


Improving your statistical inferences (Free Course)

 


There are 8 modules in this course

This course aims to help you to draw better statistical inferences from empirical research. First, we will discuss how to correctly interpret p-values, effect sizes, confidence intervals, Bayes Factors, and likelihood ratios, and how these statistics answer different questions you might be interested in. Then, you will learn how to design experiments where the false positive rate is controlled, and how to decide upon the sample size for your study, for example in order to achieve high statistical power. Subsequently, you will learn how to interpret evidence in the scientific literature given widespread publication bias, for example by learning about p-curve analysis. Finally, we will talk about how to do philosophy of science, theory construction, and cumulative science, including how to perform replication studies, why and how to pre-register your experiment, and how to share your results following Open Science principles. 

In practical, hands on assignments, you will learn how to simulate t-tests to learn which p-values you can expect, calculate likelihood ratio's and get an introduction the binomial Bayesian statistics, and learn about the positive predictive value which expresses the probability published research findings are true. We will experience the problems with optional stopping and learn how to prevent these problems by using sequential analyses. You will calculate effect sizes, see how confidence intervals work through simulations, and practice doing a-priori power analyses. Finally, you will learn how to examine whether the null hypothesis is true using equivalence testing and Bayesian statistics, and how to pre-register a study, and share your data on the Open Science Framework.

Join Free - Improving your statistical inferences


What will be the output of the following code snippet? num1 = num2 = (10, 20, 30, 40, 50) print(id(num1), type(num2)) print(isinstance(num1, tuple)) print(num1 is num2) print(num1 is not num2) print(20 in num1) print(30 not in num2)

What will be the output of the following code snippet?

num1 = num2 = (10, 20, 30, 40, 50)

  1. print(id(num1), type(num2))
  2. print(isinstance(num1, tuple))
  3. print(num1 is num2)
  4. print(num1 is not num2)
  5. print(20 in num1)
  6. print(30 not in num2)


Solution and Explanation: 

num1 and num2 are both assigned the same tuple (10, 20, 30, 40, 50).

  1. print(id(num1), type(num2)) prints the identity and type of num1. Since num1 and num2 reference the same tuple, they will have the same identity. The output will show the identity and type of the tuple.
  2. print(isinstance(num1, tuple)) checks if num1 is an instance of the tuple class and prints True because num1 is a tuple.
  3. print(num1 is num2) checks if num1 and num2 refer to the same object. Since they are both assigned the same tuple, this will print True.
  4. print(num1 is not num2) checks if num1 and num2 do not refer to the same object. Since they are the same tuple, this will print False.
  5. print(20 in num1) checks if the value 20 is present in the tuple num1. It will print True.
  6. print(30 not in num2) checks if the value 30 is not present in the tuple num2. It will print False.
The output of the code will look something like this:

(id_of_tuple, <class 'tuple'>)
True
True
False
True
False

num1 = [10, 20] num2 = [30] num1.append(num2) print(num1)

Code - 

num1 = [10, 20]

num2 = [30]

num1.append(num2)

print(num1)

Solution and Explanation :


The above code appends the list num2 as a single element to the list num1. So, num1 becomes a nested list. Here's the breakdown of the code:

num1 = [10, 20]
num2 = [30]
num1.append(num2)
print(num1)
num1 is initially [10, 20].
num2 is [30].
num1.append(num2) appends num2 as a single element to num1, resulting in num1 becoming [10, 20, [30]].
print(num1) prints the updated num1.
The output of the code will be: [10, 20, [30]]

Introduction to Microsoft Excel (Free Course)

 


What you'll learn

Create an Excel spreadsheet and learn how to maneuver around the spreadsheet for data entry.

Create simple formulas in an Excel spreadsheet to analyze data.

Learn, practice, and apply job-ready skills in less than 2 hours

Receive training from industry experts

Gain hands-on experience solving real-world job tasks

Build confidence using the latest tools and technologies

About this Guided Project

By the end of this project, you will learn how to create an Excel Spreadsheet by using a free version of Microsoft Office Excel.  

Excel is a spreadsheet that works like a database. It consists of individual cells that can be used to build functions, formulas, tables, and graphs that easily organize and analyze large amounts of information and data. Excel is organized into rows (represented by numbers) and columns (represented by letters) that contain your information. This format allows you to present large amounts of information and data in a concise and easy to follow format. Microsoft Excel is the most widely used software within the business community. Whether it is bankers or accountants or business analysts or marketing professionals or scientists or entrepreneurs, almost all professionals use Excel on a consistent basis. 

You will learn what an Excel Spreadsheet is, why we use it and the most important keyboard shortcuts, functions, and basic formulas.

Join Free - Introduction to Microsoft Excel

Thursday, 23 November 2023

Python Coding challenge - Day 75 | What is the output of the following Python code?

 


Code : 

lst = [10, 25, 4, 12, 3, 8]

sorted(lst)

print(lst)


Solution and Explanation :

The above code sorts the list lst using the sorted() function, but it doesn't modify the original list. The sorted() function returns a new sorted list without changing the original list. If you want to sort the original list in-place, you can use the sort() method of the list:


lst = [10, 25, 4, 12, 3, 8]
lst.sort()
print(lst)

This will modify the original list lst and print the sorted result. If you want to keep the original list unchanged and create a new sorted list, you can use sorted() and assign it to a new variable:

lst = [10, 25, 4, 12, 3, 8]
sorted_lst = sorted(lst)
print(sorted_lst)
print(lst)

In this case, sorted_lst will contain the sorted version of the original list, and lst will remain unchanged.






num = [10, 20, 30, 40, 50] num[2:4] = [ ] print(num)

Code :

num = [10, 20, 30, 40, 50]

num[2:4] = [ ]

print(num)


Solution and Explanation : 

In the provided code, you have a list num containing the elements [10, 20, 30, 40, 50]. Then, you use slicing to modify elements from index 2 to 3 (not including 4) by assigning an empty list [] to that slice. Let's break down the code step by step:

num = [10, 20, 30, 40, 50]

This initializes the list num with the values [10, 20, 30, 40, 50].

num[2:4] = []

This line modifies the elements at index 2 and 3 (not including 4) by assigning an empty list [] to that slice. As a result, the elements at index 2 and 3 are removed.

After this operation, the list num will be:

[10, 20, 50]

So, the final output of print(num) will be: [10, 20, 50]

Deep Learning Specialization

 


What you'll learn

Build and train deep neural networks, identify key architecture parameters, implement vectorized neural networks and deep learning to applications

Train test sets, analyze variance for DL applications, use standard techniques and optimization algorithms, and build neural networks in TensorFlow

Build a CNN and apply it to detection and recognition tasks, use neural style transfer to generate art, and apply algorithms to image and video data

Build and train RNNs, work with NLP and Word Embeddings, and use HuggingFace tokenizers and transformer models to perform NER and Question Answering

Specialization - 5 course series

The Deep Learning Specialization is a foundational program that will help you understand the capabilities, challenges, and consequences of deep learning and prepare you to participate in the development of leading-edge AI technology. 

In this Specialization, you will build and train neural network architectures such as Convolutional Neural Networks, Recurrent Neural Networks, LSTMs, Transformers, and learn how to make them better with strategies such as Dropout, BatchNorm, Xavier/He initialization, and more. Get ready to master theoretical concepts and their industry applications using Python and TensorFlow and tackle real-world cases such as speech recognition, music synthesis, chatbots, machine translation, natural language processing, and more.

AI is transforming many industries. The Deep Learning Specialization provides a pathway for you to take the definitive step in the world of AI by helping you gain the knowledge and skills to level up your career. Along the way, you will also get career advice from deep learning experts from industry and academia.

Applied Learning Project

By the end you’ll be able to:

 • Build and train deep neural networks, implement vectorized neural networks, identify architecture parameters, and apply DL to your applications

• Use best practices to train and develop test sets and analyze bias/variance for building DL applications, use standard NN techniques, apply optimization algorithms, and implement a neural network in TensorFlow

• Use strategies for reducing errors in ML systems, understand complex ML settings, and apply end-to-end, transfer, and multi-task learning

• Build a Convolutional Neural Network, apply it to visual detection and recognition tasks, use neural style transfer to generate art, and apply these algorithms to image, video, and other 2D/3D data

• Build and train Recurrent Neural Networks and its variants (GRUs, LSTMs), apply RNNs to character-level language modeling, work with NLP and Word Embeddings, and use HuggingFace tokenizers and transformers to perform Named Entity Recognition and Question Answering

JOIN Free - Deep Learning Specialization

How will you create an empty list, empty tuple, empty set and empty dictionary?

lst = [ ]

tpl = ( )

s = set( )

dct = { }


Empty List:

empty_list = []


Empty Tuple:

empty_tuple = ()


Empty Set:

empty_set = set()


Empty Dictionary:

empty_dict = {}


Alternatively, for the empty dictionary, you can use the dict() constructor as well:

empty_dict = dict()

1. print(6 // 2) 2. print(3 % -2) 3. print(-2 % -4) 4. print(17 / 4) 5. print(-5 // -3)

1. print(6 // 2)


2. print(3 % -2)


3. print(-2 % -4)


4. print(17 / 4)


5. print(-5 // -3)


Let's evaluate each expression:


print(6 // 2)

Output: 3

Explanation: // is the floor division operator, which returns the largest integer that is less than or equal to the result of the division. In this case, 6 divided by 2 is 3.


print(3 % -2)

Output: -1

Explanation: % is the modulo operator, which returns the remainder of the division. In this case, the remainder of 3 divided by -2 is -1.


print(-2 % -4)

Output: -2

Explanation: Similar to the previous example, the remainder of -2 divided by -4 is -2.


print(17 / 4)

Output: 4.25

Explanation: / is the division operator, and it returns the quotient of the division. In this case, 17 divided by 4 is 4.25.


print(-5 // -3)

Output: 1

Explanation: The floor division of -5 by -3 is 1. The result is rounded down to the nearest integer.

a = [1, 2, 3, 4] b = [1, 2, 5] print(a < b)

 In Python, when comparing lists using the less than (<) operator, the lexicographical (dictionary) order is considered. The comparison is performed element-wise until a difference is found. In your example:

a = [1, 2, 3, 4]

b = [1, 2, 5]

print(a < b)

The comparison starts with the first elements: 1 in a and 1 in b. Since they are equal, the comparison moves to the next elements: 2 in a and 2 in b. Again, they are equal. Finally, the comparison reaches the third elements: 3 in a and 5 in b. At this point, 3 is less than 5, so the result of the comparison is True.

Therefore, the output of the code will be: True

Wednesday, 22 November 2023

Python Coding challenge - Day 74 | What is the output of the following Python code?

 

Code - 

fruits = {'Kiwi', 'Jack Fruit', 'Lichi'}
fruits.clear( )
print(fruits)

Solution and Explanation: 

The variable fruits seems to be defined as a set, but you are trying to use the clear() method on it, which is applicable to dictionaries, not sets. If you want to clear a set, you can use the clear() method directly on the set. Here's the corrected code:

fruits = {'Kiwi', 'Jack Fruit', 'Lichi'}

fruits.clear()

print(fruits)

This will output an empty set:

set()

If you intended fruits to be a dictionary, you should define it using key-value pairs, like this:

fruits = {'kiwi': 1, 'jackfruit': 2, 'lichi': 3}

fruits.clear()

print(fruits)

This will output an empty dictionary:

{}

10 FREE coding courses from University of Michigan

Advanced Portfolio Construction and Analysis with Python

 


What you'll learn

Analyze style and factor exposures of portfolios  

 Implement robust estimates for the covariance matrix  

Implement Black-Litterman portfolio construction analysis  

Implement a variety of robust portfolio construction models  


There are 4 modules in this course

The practice of investment management has been transformed in recent years by computational methods. Instead of merely explaining the science, we help you build on that foundation in a practical manner, with an emphasis on the hands-on implementation of those ideas in the Python programming language. In this course, we cover the estimation, of risk and return parameters for meaningful portfolio decisions, and also introduce a variety of state-of-the-art portfolio construction techniques that have proven popular in investment management and portfolio construction due to their enhanced robustness.

As we cover the theory and math in lecture videos, we'll also implement the concepts in Python, and you'll be able to code along with us so that you have a deep and practical understanding of how those methods work. By the time you are done, not only will you have a foundational understanding of modern computational methods in investment management, you'll have practical mastery in the implementation of those methods. If you follow along and implement all the lab exercises, you will complete the course with a powerful toolkit that you will be able to use to perform your own analysis and build your own implementations and perhaps even use your newly acquired knowledge to improve on current methods. 

Join free  - Advanced Portfolio Construction and Analysis with Python

Inferential Statistical Analysis with Python

 


What you'll learn

Determine assumptions needed to calculate confidence intervals for their respective population parameters.

Create confidence intervals in Python and interpret the results.

Review how inferential procedures are applied and interpreted step by step when analyzing real data.

Run hypothesis tests in Python and interpret the results.

There are 4 modules in this course

In this course, we will explore basic principles behind using data for estimation and for assessing theories. We will analyze both categorical data and quantitative data, starting with one population techniques and expanding to handle comparisons of two populations. We will learn how to construct confidence intervals. We will also use sample data to assess whether or not a theory about the value of a parameter is consistent with the data. A major focus will be on interpreting inferential results appropriately.  

At the end of each week, learners will apply what they’ve learned using Python within the course environment. During these lab-based sessions, learners will work through tutorials focusing on specific case studies to help solidify the week’s statistical concepts, which will include further deep dives into Python libraries including Statsmodels, Pandas, and Seaborn. This course utilizes the Jupyter Notebook environment within Coursera. 

Join free - Inferential Statistical Analysis with Python

s = { } t = {1, 4, 5, 2, 3} print(type(s), type(t))

s = { }

t = {1, 4, 5, 2, 3}

print(type(s), type(t))

<class 'dict'> <class 'set'>


The first line initializes an empty dictionary s using curly braces {}, and the second line initializes a set t with the elements 1, 4, 5, 2, and 3 using curly braces as well.


The print(type(s), type(t)) statement then prints the types of s and t. When you run this code, the output will be:

<class 'dict'> <class 'set'>

This indicates that s is of type dict (dictionary) and t is of type set. If you want s to be an empty set, you should use the set() constructor:

s = set()

t = {1, 4, 5, 2, 3}

print(type(s), type(t))

With this corrected code, the output will be:

<class 'set'> <class 'set'>

Now both s and t will be of type set.

s1 = {10, 20, 30, 40, 50} s2 = {10, 20, 30, 40, 50} s3 = {*s1, *s2} print(s3) Output {40, 10, 50, 20, 30}

 s1 = {10, 20, 30, 40, 50}

s2 = {10, 20, 30, 40, 50}

s3 = {*s1, *s2}

print(s3)

Output

{40, 10, 50, 20, 30}


In the provided code, three sets s1, s2, and s3 are defined. s1 and s2 contain the same elements: 10, 20, 30, 40, and 50. Then, s3 is created by unpacking the elements of both s1 and s2. Finally, the elements of s3 are printed.

Here's the step-by-step explanation:

s1 is defined as the set {10, 20, 30, 40, 50}.

s2 is defined as the set {10, 20, 30, 40, 50}, which is the same as s1.

s3 is defined as the set resulting from unpacking the elements of both s1 and s2 using the * operator. This means that the elements of s1 and s2 are combined into a new set.

The print statement prints the elements of the set s3.

Since sets do not allow duplicate elements, the resulting set s3 will still have only unique elements. In this case, the output of the code will be:

{10, 20, 30, 40, 50}

Tuesday, 21 November 2023

Python Coding challenge - Day 73 | What is the output of the following Python code?

 


Code - 

i, j, k = 4, -1, 0

w = i or j or k      # w = (4 or -1) or 0 = 4

x = i and j and k    # x = (4 and -1) and 0 = 0

y = i or j and k     # y = (4 or -1) and 0 = 4

z = i and j or k     # z = (4 and -1) or 0 = -1

print(w, x, y, z)

Solution and Explanation - 

Here's the explanation for each variable:

w: It takes the first non-zero value from left to right in the sequence (i, j, k). In this case, the first non-zero value is 4.
x: It takes the first zero value from left to right in the sequence (i, j, k). In this case, the first zero value is 0.
y: It takes the first non-zero value from left to right in the sequence (i, j) and then evaluates the result with k using the "and" operator. In this case, (4 or -1) evaluates to 4, and 4 and 0 evaluates to 0.
z: It takes the first non-zero value from left to right in the sequence (i, j) and then evaluates the result with k using the "or" operator. In this case, (4 and -1) evaluates to -1, and -1 or 0 evaluates to -1.

So, the output of the print statement will be: 4 0 4 -1


From Excel to Power BI (Free Course)

 


What you'll learn

Learners will be instructed in how to make use of Excel and Power BI to collect, maintain, share and collaborate, and to make data driven decisions

There is 1 module in this course

Are you using Excel to manage, analyze, and visualize your data? Would you like to do more? Perhaps you've considered Power BI as an alternative, but have been intimidated by the idea of working in an advanced environment. The fact is, many of the same tools and mechanisms exist across both these Microsoft products. This means Excel users are actually uniquely positioned to transition to data modeling and visualization in Power BI! Using methods that will feel familiar, you can learn to use Power BI to make data-driven business decisions using large volumes of data. 


We will help you to build fundamental Power BI knowledge and skills, including: 

Importing data from Excel and other locations into Power BI.

Understanding the Power BI environment and its three Views.

Building beginner-to-moderate level skills for navigating the Power BI product.

Exploring influential relationships within datasets. 

Designing Power BI visuals and reports.

Building effective dashboards for sharing, presenting, and collaborating with peers in Power BI Service.


For this course you will need:

A basic understanding of data analysis processes in Excel.

At least a free Power BI licensed account, including:

The Power BI desktop application.

Power BI Online in Microsoft 365.

Course duration is approximately three hours. Learning is divided into five modules, the fifth being a cumulative assessment. The curriculum design includes video lessons, interactive learning using short, how-to video tutorials, and practice opportunities using COMPLIMENTARY DATASETS. Intended audiences include business students, small business owners, administrative assistants, accountants, retail managers, estimators, project managers, business analysts, and anyone who is inclined to make data-driven business decisions. Join us for the journey!

Join Free - From Excel to Power BI

Meta Front-End Developer Professional Certificate

 


What you'll learn

Create a responsive website using HTML to structure content, CSS to handle visual style, and JavaScript to develop interactive experiences. 

Learn to use React in relation to Javascript libraries and frameworks.

Learn Bootstrap CSS Framework to create webpages and work with GitHub repositories and version control.

Prepare for a coding interview, learn best approaches to problem-solving, and build portfolio-ready projects you can share during job interviews.


Prepare for a career in Front-end Development

Receive professional-level training from Meta

Demonstrate your proficiency in portfolio-ready projects

Earn an employer-recognized certificate from Meta

Qualify for in-demand job titles: Front-End Developer, Website Developer, Software Engineer


Professional Certificate - 9 course series

Want to get started in the world of coding and build websites as a career? This certificate, designed by the software engineering experts at Meta—the creators of Facebook and Instagram, will prepare you for a career as a front-end developer.

In this program, you’ll learn: 

How to code and build interactive web pages using HTML5, CSS and JavaScript. 

In-demand design skills to create professional page layouts using industry-standard tools such as Bootstrap, React, and Figma. 

GitHub repositories for version control, content management system (CMS) and how to edit images using Figma. 

How to prepare for technical interviews for front-end developer roles.

By the end, you’ll put your new skills to work by completing a real-world project where you’ll create your own front-end web application. Any third-party trademarks and other intellectual property (including logos and icons) referenced in the learning experience remain the property of their respective owners. Unless specifically identified as such, Coursera’s use of third-party intellectual property does not indicate any relationship, sponsorship, or endorsement between Coursera and the owners of these trademarks or other intellectual property.

Applied Learning Project

Throughout the program, you’ll engage in hands-on activities that offer opportunities to practice and implement what you are learning. You’ll complete hands-on projects that you can showcase during job interviews and on relevant social networks.

At the end of each course, you’ll complete a project to test your new skills and ensure you understand the criteria before moving on to the next course. There are 9 projects in which you’ll use a lab environment or a web application to perform tasks such as:  

Edit your Bio page—using your skills in HTML5, CSS and UI frameworks

Manage a project in GitHub—using version control in Git, Git repositories and the Linux Terminal 

Build a static version of an application—you’ll apply your understanding of React, frameworks, routing, hooks, bundlers and data fetching. 

At the end of the program, there will be a Capstone project where you will bring your new skillset together to create the front-end web application.

Join - Meta Front-End Developer Professional Certificate

Introduction to Statistics (Free Course)

 


There are 12 modules in this course

Stanford's "Introduction to Statistics" teaches you statistical thinking concepts that are essential for learning from data and communicating insights. By the end of the course, you will be able to perform exploratory data analysis, understand key principles of sampling, and select appropriate tests of significance for multiple contexts. You will gain the foundational skills that prepare you to pursue more advanced topics in statistical thinking and machine learning.

Topics include Descriptive Statistics, Sampling and Randomized Controlled Experiments, Probability, Sampling Distributions and the Central Limit Theorem, Regression, Common Tests of Significance, Resampling, Multiple Comparisons.

Free Course - Introduction to Statistics





IBM Full Stack Software Developer Professional Certificate

 


What you'll learn

Master the most up-to-date practical skills and tools that full stack developers use in their daily roles

Learn how to deploy and scale applications using Cloud Native methodologies and tools such as Containers, Kubernetes, Microservices, and Serverless

Develop software with front-end development languages and tools such as HTML, CSS, JavaScript, React, and Bootstrap

Build your GitHub portfolio by applying your skills to multiple labs and hands-on projects, including a capstone

Professional Certificate - 12 course series

Prepare for a career in the high-growth field of software development. In this program, you’ll learn in-demand skills and tools used by professionals for front-end, back-end, and cloud native application development to get job-ready in less than 4 months, with no prior experience needed. 

Full stack refers to the end-to-end computer system application, including the front end and back end coding. This Professional Certificate covers development for both of these scenarios. Cloud native development refers to developing a program designed to work on cloud architecture. The flexibility and adaptability that full stack and cloud native developers provide make them highly sought after in this digital world. 

You’ll  learn how to build, deploy, test, run, and manage full stack cloud native applications. Technologies covered includes Cloud foundations, GitHub, Node.js, React, CI/CD, Containers, Docker, Kubernetes, OpenShift, Istio, Databases, NoSQL, Django ORM, Bootstrap, Application Security, Microservices, Serverless computing, and more. 

After completing the program you will have developed several applications using front-end and back-end technologies and deployed them on a cloud platform using Cloud Native methodologies. You will publish these projects through your GitHub repository to share your portfolio with your peers and prospective employers.

This program is ACE® recommended—when you complete, you can earn up to 18 college credits.

Applied Learning Project

Throughout the courses in the Professional Certificate, you will develop a portfolio of hands-on projects involving various popular technologies and programming languages in Full Stack Cloud Application Development. These projects include creating:

HTML pages on Cloud Object Storage

An interest rate calculator using HTML, CSS, and JavaScript

An AI program deployed on Cloud Foundry using DevOps principles and CI/CD toolchains with a NoSQL database

A Node.js back-end application and a React front-end application

A containerized guestbook app packaged with Docker deployed with Kubernetes and managed with OpenShift

A Python app bundled as a package

A database-powered application using Django ORM and Bootstrap

An app built using Microservices & Serverless

A scalable, Cloud Native Full Stack application using the technologies learned in previous courses

You will publish these projects through your GitHub repository to share your skills with your peers and prospective employers.

Join - IBM Full Stack Software Developer Professional Certificate

Meta Back-End Developer Professional Certificate

 


What you'll learn

Gain the technical skills required to become a qualified back-end developer

Learn to use programming systems including Python Syntax, Linux commands, Git, SQL, Version Control, Cloud Hosting, APIs, JSON, XML and more

Build a portfolio using your new skills and begin interview preparation including tips for what to expect when interviewing for engineering jobs

Learn in-demand programming skills and how to confidently use code to solve problems

Professional Certificate - 9 course series

Ready to gain new skills and the tools developers use to create websites and web applications? This certificate, designed by the software engineering experts at  Meta—the creators of Facebook and Instagram, will prepare you for an entry-level career as a back-end developer. 


In this program, you’ll learn:

Python Syntax—the most popular choice for machine learning, data science and artificial intelligence.

In-demand programming skills and how to confidently use code to solve problems. 

Linux commands and Git repositories to implement version control.

The world of data storage and databases using MySQL, and how to craft sophisticated SQL queries. 

Django web framework and how the front-end consumes data from the REST APIs. 

How to prepare for technical interviews for back-end developer roles.

Any third-party trademarks and other intellectual property (including logos and icons) referenced in the learning experience remain the property of their respective owners. Unless specifically identified as such, Coursera’s use of third-party intellectual property does not indicate any relationship, sponsorship, or endorsement between Coursera and the owners of these trademarks or other intellectual property.

Applied Learning Project

Throughout the program, you’ll engage in applied learning through hands-on activities to help level up your knowledge. At the end of each course, you’ll complete 10 micro-projects that will help prepare you for the next steps in your engineer career journey. 

In these projects, you’ll use a lab environment or a web application to perform tasks such as:   

Solve problems using Python code. 

Manage a project in GitHub using version control in Git, Git repositories and the Linux Terminal. 

Design and build a simple Django app. 

At the end of the program, there will be a Capstone project where you will bring all of your knowledge together to create a Django web app.

Join - Meta Back-End Developer Professional Certificate

Monday, 20 November 2023

MITx: Machine Learning with Python: from Linear Models to Deep Learning (Free Course)

 


What you'll learn

Understand principles behind machine learning problems such as classification, regression, clustering, and reinforcement learning

Implement and analyze models such as linear models, kernel machines, neural networks, and graphical models

Choose suitable models for different applications

Implement and organize machine learning projects, from training, validation, parameter tuning, to feature engineering.

Syllabus

Lectures :

Introduction

Linear classifiers, separability, perceptron algorithm

Maximum margin hyperplane, loss, regularization

Stochastic gradient descent, over-fitting, generalization

Linear regression

Recommender problems, collaborative filtering

Non-linear classification, kernels

Learning features, Neural networks

Deep learning, back propagation

Recurrent neural networks

Generalization, complexity, VC-dimension

Unsupervised learning: clustering

Generative models, mixtures

Mixtures and the EM algorithm

Learning to control: Reinforcement learning

Reinforcement learning continued

Applications: Natural Language Processing

Projects :

Automatic Review Analyzer

Digit Recognition with Neural Networks

Reinforcement Learning


Join Free - MITx: Machine Learning with Python: from Linear Models to Deep Learning

IBM: Machine Learning with Python: A Practical Introduction (Free Course)

 


About this course

Please Note: Learners who successfully complete this IBM course can earn a skill badge — a detailed, verifiable and digital credential that profiles the knowledge and skills you’ve acquired in this course. Enroll to learn more, complete the course and claim your badge!

This Machine Learning with Python course dives into the basics of machine learning using Python, an approachable and well-known programming language. You'll learn about supervised vs. unsupervised learning, look into how statistical modeling relates to machine learning, and do a comparison of each.

We'll explore many popular algorithms including Classification, Regression, Clustering, and Dimensional Reduction and popular models such as Train/Test Split, Root Mean Squared Error (RMSE), and Random Forests. Along the way, you’ll look at real-life examples of machine learning and see how it affects society in ways you may not have guessed!

Most importantly, you will transform your theoretical knowledge into practical skill using hands-on labs. Get ready to do more learning than your machine!

We'll explore many popular algorithms including Classification, Regression, Clustering, and Dimensional Reduction and popular models such asTrain/Test Split, Root Mean Squared Error and Random Forests.

Mostimportantly, you will transform your theoretical knowledge into practical skill using hands-on labs. Get ready to do more learning than your machine!

Join Free - IBM: Machine Learning with Python: A Practical Introduction

Saturday, 18 November 2023

Write a program to generate all Pythagorean Triplets with side length less than or equal to 50.

 Certainly! Let me explain the code step by step:

# Function to check if a, b, c form a Pythagorean triplet

def is_pythagorean_triplet(a, b, c):

    return a**2 + b**2 == c**2

This part defines a function is_pythagorean_triplet that takes three arguments (a, b, and c) and returns True if they form a Pythagorean triplet (satisfy the Pythagorean theorem), and False otherwise.

# Generate and print all Pythagorean triplets with side lengths <= 50

for a in range(1, 51):

    for b in range(a, 51):

Here, two nested for loops are used. The outer loop iterates over values of a from 1 to 50. The inner loop iterates over values of b from a to 50. The inner loop starts from a to avoid duplicate triplets (e.g., (3, 4, 5) and (4, 3, 5) are considered duplicates).

        c = (a**2 + b**2)**0.5  # Calculate c using the Pythagorean theorem

        if c.is_integer() and c <= 50:

            print(f"Pythagorean Triplet: ({a}, {b}, {int(c)})")

Within the loops, the program calculates the value of c using the Pythagorean theorem (c = sqrt(a^2 + b^2)). The is_integer() method is then used to check if c is a whole number. If it is, and if c is less than or equal to 50, the triplet (a, b, c) is printed as a Pythagorean triplet.


# Function to check if a, b, c form a Pythagorean triplet

def is_pythagorean_triplet(a, b, c):

    return a**2 + b**2 == c**2


# Generate and print all Pythagorean triplets with side lengths <= 50

for a in range(1, 51):

    for b in range(a, 51):

        c = (a**2 + b**2)**0.5  # Calculate c using the Pythagorean theorem

        if c.is_integer() and c <= 50:

            print(f"Pythagorean Triplet: ({a}, {b}, {int(c)})")


Rewrite the following program using for loop. lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose'] s = 'Mumbai' i = 0 while i < len(lst) : if i > 3 : break else : print(i, lst[i], s[i]) i += 1

 Rewrite the following program using for loop.

lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose']

s = 'Mumbai'

i = 0

while i < len(lst) :

if i > 3 :

break

else :

print(i, lst[i], s[i])

i += 1


Here's the equivalent program using a for loop:

lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose']

s = 'Mumbai'

for i in range(len(lst)):

    if i > 3:

        break

    else:

        print(i, lst[i], s[i])

In this version, the for loop iterates over the indices of the lst list using range(len(lst)). The if condition inside the loop checks whether i is greater than 3, and if so, it breaks out of the loop. Otherwise, it prints the values of i, lst[i], and s[i]. The loop increment is handled automatically by the for loop construct, eliminating the need for an explicit increment (i += 1).






Write a program to print first 25 odd numbers using range( ).

 You can use the range() function with a step of 2 to generate odd numbers and then use a loop to print the first 25 odd numbers. Here's a simple Python program to achieve this:

# Using range() to generate the first 25 odd numbers

odd_numbers = list(range(1, 50, 2))[:25]

# Printing the first 25 odd numbers

for number in odd_numbers:

    print(number)

In this program:

range(1, 50, 2) generates odd numbers starting from 1, up to, but not including 50, with a step of 2.

[:25] is used to select the first 25 numbers from the list generated by range().

The loop then prints each of the first 25 odd numbers.






Popular Posts

Categories

100 Python Programs for Beginner (53) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (932) Python Coding Challenge (358) Python Quiz (23) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses