Skip to main content

Posts

Find String Of Maximum length Inside A String Sentence Using Python For Loop

  Small Python Program For Beginners To Practice In this article, we are going to write a Python Code to Print out the maximum string of length inside a string. For this, first, we break the string sentence at the space and then proceed with the code. If you are looking for a Python Tutorial series then it's here example = "Hello My name is Ninza and I am a developer" x = example.split(' ') print(x) print(len(x)) max_len = -1 for element in x: if len(element) > max_len: max_len = len(element) response = element print(response) The output of the code is: ['Hello', 'My', 'name', 'is', 'Ninza', 'and', 'I', 'am', 'a', 'developer'] 10 developer

Print Fibonacci Series In Python Using For Loop

  Fibonacci Series Using Python For Loop In this article, we are going to print the Fibonacci series Using Python For loop. This term of the series is the sum of two predecessor terms of the series. That's why it goes like, 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. If you are looking for a Python Tutorial Series then it's here def number(n): a = 0 b = 1 sum = 0 for count in range(1,n+1): print(sum, end=' ') count +=1 a = b b = sum sum = a+b print() number(10) The output of the code is: 0 1 1 2 3 5 8 13 21 34

Hollow Hour Glass or Hollow Sand Glass Program in Python

  Small Python Program For Beginners To Practice In this article, we are going to write python code to print out hollow hour glass as shown in the featured Image. If you are looking for a Python Tutorial series then it's here The python code we are going to write is a combination of normal hollow pyramid and Inverted hollow pyramid . we are going to combine both of them to get the desired output. def sand(n): for i in range(1, n+1): for j in range(1, i): print(" ", end="") for j in range(1, (n*2 - (2*i - 1))+1): if i == 1 or j == 1 or j ==(n*2 -(2*i-1)): print("*", end="") else: print(" ", end="") print() for i in range(2,n+1): for j in range(n-i): print(" ", end="") for j in range(1, (2*i-1)+1): if i == n or j == 1 or j == (2*i-1): print(&#

Python Hour Glass (Sand Glass) Program In Python

  Small Python For Beginners to Practice In this article, we are going to print a Sandglass star pattern using Python as you can see in the featured image. If you are looking for a Python Tutorial Series then it's here If you look closely then this Hourglass pattern is a combination of a normal pyramid and inverted pyramid program in Python. So we will combine both of these programs to print out the Hourglass star pattern. def glass(rows): spaces = 0 stars2 = 3 spaces2 = rows-2 stars = 2*rows-1 for i in range(1, rows+1): print(' ' * spaces + '*' * stars) stars -=2 spaces +=1 for i in range(1, rows): print(' '*spaces2 + '*'*stars2) stars2 += 2 spaces2 -= 1 glass(10) The output of the program is: ******************* ***************** *************** ************* *********** ********* ******* ***** *** * ***

Write a program to print reverse counting from 10 to 1 using while loop in Python

  Python For Beginners to Practice In this article, we are going to write a Python program to print numbers in reverse order using a while loop.  First, we will print the reverse count of numbers 10 to 1. Then we will write a program to print the reverse of the numbers using the user's input. If you are looking for a python tutorial series then it's here count = 10 while True: print(count) count -= 1 if count == 0: break else: pass The output of the code is: 10 9 8 7 6 5 4 3 2 1 If you want to take input of integer from the user then you can do this using the following way: count = int(input("Enter the number: ")) while True: print(count) count -= 1 if count == 0: break else: pass The output of the code is: Enter the number: 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

Horizontal Triangle Star Pattern Code In Python

Small python Program for beginners In this article, we are going to print out a horizontal triangle as shown in the featured image using Python. If you are looking for a Python Tutorial Series then it's here def pattern(n): for i in range(1,n+1): for j in range(1,i+1): print('*', end='') print('') for i in range(n, 1, -1): for j in range(0, i-1): print('*', end='') print('') pattern(10) The output of the above code is: * ** *** **** ***** ****** ******* ******** ********* ********** ********* ******** ******* ****** ***** **** *** ** *

Program Of Hollow Pyramid or Triangle in Python

Small Star Python Program for Beginners   In this article, we are going to print out the hollow triangle or pyramid in python. If you are looking for a Python tutorial series then it's here def pyramid(num): for i in range(1,num+1): for j in range(num-i): print(" ", end="") for j in range(1, (2*i-1)+1): if i == num or j == 1 or j == (2*i-1): print('*', end='') else: print(" ", end="") print() pyramid(10) The output of the program is: * * * * * * * * * * * * * * * * * *******************