Posts

Showing posts with the label python for beginners

Python 3 exercise with solutions (Set 1)

Image
  1.To convert the given kilometres into metre and feet. #For this problem the only thing you need to know is the formula to convert km into metre and feet. Output: 2.To find whether the given year is leap year or ordinary year. #In this problem we have made use of "and" & "or" functions , so that the problem can be solved in a brief and concise manner. Output: 3.To find the sum of n terms. #Here while loop is used over the condition i<=n, so that repeated addition is performed, provided the sum=sum+i, until i falls out of the loop condition. Output: 4.To find the square of sum of n terms. #its similar to the previous problem the one thing you are supposed to consider is the square of numbers , that's it you could land on the answer Output: 5.To print the pattern below,             *             * *             * * *             * * * *             * * * * * #inorder to print the pattern, two variables such as i and j are used to denote row and column res

How to write Algorithms

How to write Algorithms for solving problems? Algorithm: An algorithm is the set of rules that are needed to be followed while solving problems. Here we'll learn how to write algorithms for the given simple problems. Tips for writing an algorithm : Read the problem carefully. Don't start writing the code immediately. It is always best to start with the algorithm. After understanding the problem, think about the logic required to solve the problem. Once you root out the logic behind the problem, then start writing the algorithm which is nothing but the procedures of solving the problem in a step wise manner. Problem 1: To check whether the given number is positive or negative. Input:  A number Output:  Positive or negative Procedure: Step 1 : Start Step 2 : Read the number(n) from the user. Step 3 : If the number is less than zero, print "negative". If the number is greater than zero, print "positive". Step 4 : End Problem 2: To check whether the given number