Posts

Showing posts from April, 2021

Python Program To Print Diamond Pattern

Image
  In this post,  we are going to write a python program to print a diamond pattern of * like this. General idea : To print this diamond, we need to divide the diamond into two parts. One triangle with base down, then the triangle with base upwards. First, we need to print the triangle with base down, the triangle with base up. In the first row of the first triangle with base down, there are 4 spaces and then the * is printed. In the second row of the same triangle, there are 3 spaces and the 3 * are printed. In the third row 2 spaces and 5 * are printed and in the fourth row 1 space and 7 * printed. Finally, in the last row, no space, and 9 * are printed. Here the spaces are decreasing by 1 and no of * increasing by 2. In the first row of the second triangle with base upwards. 1 space and 7 * are printed. In the second row 2 spaces and 5 * printed. Then finally 4 spaces and 1 * are printed. In this one, the number of spaces is increasing by 1, and the number of * is decreasing...

Python program to print the solutions of the given equation - Codicaly

Image
  In this post, we are going to write a program to find the solutions of the inputted quadratic equation. What are the Solutions of the Quadratic equation ? A quadratic equation is an equation with degree 2, i.e, the maximum power of the variable is 2. The general form of the quadratic equation is as follows.  Here 'a' is the coefficient of x^2, 'b' is the coefficient of x and c is the constant.  The solutions to that equation can be easily determined using the coefficients and the constants. The formula for that is below. Pre - requisites : Python basics Program : a=int(input('Enter the coefficient of x^2 with sign')) b=int(input('Enter the coefficient of x with sign')) c=int(input('Enter the constant with sign')) x1=(-b+(b**2-4*a*c)**(1/2))/(2*a) x2=(-b-(b**2-4*a*c)**(1/2))/(2*a) print("Solutions of the equation ",a,"x^2+(",b,")x +(",c,")",' are' ,x1,'and',x2) Explanations : 1. To find the...

Python program to print prime numbers less an inputted number - Codicaly

Image
          In this post, we are going to discuss how to write a python program to print the prime numbers less than an inputted number. We already posted a how-to check whether the inputted number is prime or composite.  I highly recommend reading that and come here by clicking the link below. Link to the post :  https://codicaly.blogspot.com/2021/04/python-program-to-find-given-number-is.html What is a Prime or Composite number ? A prime number is a number that has only two factors i.e, 1, and the number itself.  A composite number is a number that has more than two factors. A number is said to factor that when it divides the other number it leaves no remainder.  Generally, the factors lie between 1 and the number itself. Pre-requisites : Python Basics List Concept Conditional statements ( Nested for-loop ) Program : u=int(input('Enter the upper limit')) for i in range(2,u+1):#Primary for loop     l=[]     for j in range(1...

Python program to check whether the inputted string is a Palindrome or not - Codicaly

Image
  In this post, we are going to check whether an inputted string is a Palindrome or not. What is Palindrome ?               A Palindrome  is a word, number, phrase, or other sequence of characters that reads the same backward as forward, such as madam or racecar. That means if the reverse of the inputted string is the same as that of the original, it is Palindrome otherwise not. Pre-requisites : Python Basics Strings concept Conditional statements. Program : a=input('Enter the phrase : ') reverse=a[::-1] if (reverse==a):     print(a,'is a pallindrome') else:     print(a,'is not a pallindrome') Explanation : 1. First we need to input the word for which we need to check it is a Palindrome or not. Using the input function we are inputting the phrase. Here we are not specifying anything before input like int or float. Hence it would take as a string that is the default. 2. To check we need to compare the reverse of the phr...

Python - Program to find the given number is a prime or composite number

Image
  In this post, we are going to check whether an inputted number is a prime number or a composite number. What is a Prime number or a Composite number ?     A prime number is a number that has only two factors i.e, 1, and the number itself.  A composite number is a number that has more than two factors. A number is said to factor that when it divides the other number it leaves no remainder.  Generally, the factors lie between 1 and the number itself. Pre-requisites : Python introduction List concept Conditional statements  Program :  a=int(input("Enter the integer:")) list1=[] # empty list for factors for i in range(1, a+1):     if (a%i==0):         list1.append(i) if len(list1)== 2:     print("The given number ",a," is a prime number.") else :     print("The given number ",a," is a composite number.") Explanation :    1. First, we need to input the integer that we need to find is prime o...