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

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

Output:

case 1:
Enter any number 95
Number is not -ve
>>>
case 2:
Enter any number -45
Number is -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 not -ve
>>>
case 2:
Enter any number -54
Number is -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 not -ve
>>>
case 2:
Enter any number -9
Number is -ve
>>>

You May Also Like:

Python Program to Check Number is zero, +ve or -ve
C Language Program to Find Factorial of Number Using Loop
Python Program to Print Fibonacci Series
Python Program to check character is an upper case alphabet or not
C Language Program for Prime Number upto 100

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


Visitor Counter

0142291