Ad Code

Responsive Advertisement

Basic Python Program - 42

Question 42: Write a Python function that takes a number as a parameter and check the number is prime or not.
Download hole Program / Project code, by clicking following link:
What is the output of the following program?
def myfunc(text, num):
    while num > 0:
        print(text)
    num = num - 1
myfunc('Hello', 4)

Given, provided a Python function named myfunc that takes two arguments: text and num. The function is intended to print the text a specified number of times based on the value of num. However, there is an issue with the indentation in your code. In Python, proper indentation is essential for defining the scope of a block of code.

Here's the corrected code:
def myfunc(text, num):
    while num > 0:
        print(text)
         num = num - 1
myfunc('Hello', 4)
In this corrected code:
  • The myfunc function is defined with the proper indentation.
  • Inside the function, there is a while loop that prints the text and decrements num by 1 in each iteration until num becomes 0.
  • Finally, the myfunc function is called with the arguments 'Hello' and 4, which will print "Hello" four times.
Programming Code:
Following code write in: BP_P42.py
# Python function

# check number is prime or not

def prime_or_not(num):
    for i in range(2, num):
        if num % i == 0:
            return (f"{num} is not Prime number.")
    
    return (f"{num} is Prime number.")
    
num = int(input("Enter a Integer number: "))

print("The given number is: ", num)

print(prime_or_not(num))            # call by value 

# Thanks for Reading.
Output:

Post a Comment

0 Comments

Ad Code

Responsive Advertisement