Skip to main content

Featured

Introduction to Numpy Library in Python

Introduction to Numpy Library in Python NUMPY - Introduction Introduction     NUMPY stands for Numerical Python. Numpy is one of the libraries for the python programming language. It is used for high level mathematical calculations. It has the large collection of functions for working with the multi-dimensional arrays, matrices, linear algebra, Fourier transform, etc. Installation of Numpy 1. Open the command or terminal on your system. 2. Enter the following command below.      #installation of NUMPY using PIP      pip install numpy       (OR)       #installation of NUMPY using CONDA      conda install numpy 3. Now, NUMPY installed on your system. To verify that use the command below.      #check for version of NUMPY      numpy --version  Tip : Use Anaconda Navigator , it comes with built-in software of JUPYTER NOTEBOOKS and pre-installed packages like Nump...

Program for Hackerrank FizzBuzz Code in Python

Python - Hackerrank FizzBuzz Program

Python - Hackerrank FizzBuzz Program
Python - Hackerrank FizzBuzz Program


Source Code

Aim :

    To program a Hackerrank FizzBuzz code in python. 

Algorithm :

  • Get the required input from the user by using input statement for 'n'(number).
  • Call the fizzBuzz() function with passing parameter as 'n'.
  • Write the required fizzBuzz function definition.
  • Display the result with the help of print statement

Program :

# Complete the 'fizzBuzz' function below.
# The function accepts INTEGER n as parameter.
def fizzBuzz(n):
    for i in range(1,n+1):
        if(i%3==0 and i%5==0):
            print("FizzBuzz")
        elif(i%3==0):
            print("Fizz")
        elif(i%5==0):
            print("Buzz")
        else:
            print(i)

if __name__ == '__main__':
    n = int(input("Enter the number : ").strip())
    fizzBuzz(n)

Output :

Enter the number : 15
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

Terminal Code :

Python - Hackerrank FizzBuzz Program
Python - Hackerrank FizzBuzz Program


Terminal Output :

Python - Hackerrank FizzBuzz Output
Python - Hackerrank FizzBuzz Output


Result :

    The output was executed successfully and result was verified.


Personal Writings for Readers!!!

Story behind single family described in Pandemic Family Book.


Read more on...

Paperback - https://amzn.to/34NS6Sk

Amazon Kindle - https://amzn.to/3aKtIng

Kobo Writing - https://bit.ly/3iQysNy

Comments

Popular Posts