All Python Programs

All Programs

Basic Python Programs

Simple Python programs

If Condition Programs

If condition based Python Programs 

Looping based programs

program based on for loop, while loop, range

Searching and Sorting

Python Searching Programs
Python Sorting Programs

Python program to check number is +ve or not.

Solution with out using functions
Solution using functions without passing arguments
Solution using functions and by passing arguments


Solution : Without using function
Program/Source Code

For better understanding of this example, one should have the knowledge of the following Python programming topics:

Python if…else… Statement
Python if…else…if…else… Statement
Python if…elif…if…elif…else… Statement

Program to check number is +ve ot not

n=int(input("Enter any number "))
if(n>0):
    print("Number is +ve")
else:
    print("Number is not +ve")

Try The Code

Output:

case 1:
Enter any number 95
Number is +ve
>>>
case 2:
Enter any number -45
Number is not +ve
>>>



Solution : Using function Without Passing Arguments
Program/Source Code

#function definition
def check():
    n=int(input("Enter any number "))
    if(n>0):
        print("Number is +ve")
    else:
        print("Number is not +ve")

#function calling
check()

Output:

case 1:
Enter any number 25
Number is +ve
>>>
case 2:
Enter any number -54
Number is not +ve
>>>



Solution : Using function Passing Arguments
Program/Source Code

#function definition
def check(n):
    if(n>0):
        print("Number is +ve")
    else:
        print("Number is not +ve")

#function calling
n=int(input("Enter any number "))
check(n)

Output:

case 1:
Enter any number 6
Number is +ve
>>>
case 2:
Enter any number -9
Number is not +ve
>>>

 

You May Also Like:

Python Program to Check Number is zero, Odd or Even
Python Program to Find Factorial of Number Using Loop
C Language Program to Print Fibonacci Series
Python Program for Prime Number
Python Program to check character is an alphabet or not
C Language Program for Prime Number

Tutorials

Technical Questions and Important programs

Interview Questions

C Programming
C++ Programming
Basic Python Tutorial
Advanced Python Tutorial
C Language
C++ Programming
Python programming
C Important Programs
C Interview Questions
C++ Interview Questions
Python Interview Questions
HTML Interview Questions