Question

In: Computer Science

Respond to the following in a minimum of 175 words: One of the most important concepts...

Respond to the following in a minimum of 175 words:

One of the most important concepts of programming is handling input and output. The following activity will allow you to get familiar with this concept specifically when using PYTHON.

   

Write a function to add two values and display the results. (Please show me where indentation goes as well, I'm not only seeking guidance on answers I'm trying to understand this so I can learn).

Discuss the steps in your thought process as you created the code, any issues you encountered, and how you solved those issues.   

Solutions

Expert Solution

Most of the programming languages supports provides curly braces to indicate the starting point and ending point of a block as well as for functions also. But in python the indentation is very useful for formation of a block, and this will help us to know which statements will execute under a specific block.

Let’s have a comparison

In C++ Programming language

In Python

int add(int a, int b)

{

int c;

c=a+b;

return c;

}

def add(a,b)

c=a+b

return c

The above program will execute smoothly.

Will yield to error as indentation error. Because compiler will unable to identify that which statements are included under the add function.

So for this we have to allow a space before c=a+b and also before return c. So the rectified program will be

For indentation minimum one space must required. But as a good programmer you may use 3 to 5 spaces as indent.

If in a block a number of statements are to be execute then all the statements should maintain same indent otherwise it will lead to error.

Example : THE BELOW PROGRAM WILL SHOW INDENTATION ERROR

AFTER PROVIDING INDENT AT LINE NUMBER 3 AGAIN IT WILL SHOW ERROR SINCE RETURN STATEMENT ALSO BELONGS TO THE METHOD

CORRECT PROGRAM CODE TO ADD TWO NUMBERS

The statements 5,6,7,9 are not indented since these does not belongs to the function add()


Related Solutions

Respond to the following in a minimum of 175 words: It is important to program your...
Respond to the following in a minimum of 175 words: It is important to program your code efficiently. Efficient code manages errors and exceptions and cleans up memory after it ends. The try-except statements are helpful in handling errors that are detected during execution. What are the two categories of errors when debugging code? How can the try-except statements handle errors in Python? Provide a code example that supports your comments.
Respond to the following in a minimum of 175 words: Why is it important to keep...
Respond to the following in a minimum of 175 words: Why is it important to keep your product in the growth stage for as long as possible?
Respond to the following in a minimum of 175 words: The most frequently used measures of...
Respond to the following in a minimum of 175 words: The most frequently used measures of central tendency for quantitative data are the mean and the median. The following table shows civil service examination scores from 24 applicants to law enforcement jobs: 83 74 85 79 82 67 78 70 18 93 64 27 93 98 82 78 68 82 83 99 96 62 93 58 Using Excel, find the mean, standard deviation, and 5-number summary of this sample. Construct...
Respond to the following in a minimum of 175 words: Explain why responsive design is important...
Respond to the following in a minimum of 175 words: Explain why responsive design is important in today's landscape. What do websites risk if they decide not to address responsive design?
Respond to the following in a minimum of 175 words, please type response: An important part...
Respond to the following in a minimum of 175 words, please type response: An important part of using statistics is being able to explain your results to decision makers. Imagine that you have conducted a two-sample test and determined that the difference was not statistically significant.   While one mean was 4.3 and the other was 3.9, the p level for the t test was p=.07. Your management team says, “Well, the difference may not be statistically significant, but the difference is...
Respond to one of the following in a minimum of 175 words: 1) Discuss: What are...
Respond to one of the following in a minimum of 175 words: 1) Discuss: What are the limitations of GDP as a measurement tool?
Please respond to the following in a minimum of 175 words: Winning one of the big...
Please respond to the following in a minimum of 175 words: Winning one of the big national lotteries provides a choice of how to receive the money. You can receive a much-reduced lump sum (like half or so) today, or the full amount in twenty annual payments starting today. Discuss how you can determine which financial deal is better. Also, what are the non-financial aspects of winning the lottery and how do they influence which option to take?
Respond to the following in a minimum of 175 words: What is the purpose of an...
Respond to the following in a minimum of 175 words: What is the purpose of an income statement, and who is the audience for this document? What components do income statements typically contain? Why?
Respond to the following in a minimum of 175 words: What is the purpose of a...
Respond to the following in a minimum of 175 words: What is the purpose of a Comprehensive Annual Financial Report, or CAFR? What standards must a CAFR comply with? What statements comprise a CAFR?
Respond to the following in a minimum of 175 words: In the early weeks of this...
Respond to the following in a minimum of 175 words: In the early weeks of this course, you learned some valuable skills for communicating within and improving the performance of teams you might be working with. This week, we will explore two crucial aspects of being on a team. We will learn about leadership and what it takes to be a good leader. We also examine conflict management and learn some ways to navigate through the inevitability of encountering conflict....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT