0% found this document useful (0 votes)
2 views1 page

Python Input-Based Program Examples

The document contains Python programming examples focused on input-based programs, including basic operations like addition, checking positive or negative numbers, and looping. It also covers functions for calculating squares, finding the largest of two numbers, summing up to N, determining even or odd, calculating factorials, generating multiplication tables, and implementing bubble sort and linear search. Each example is presented with code snippets for practical understanding.

Uploaded by

arsalansial007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Python Input-Based Program Examples

The document contains Python programming examples focused on input-based programs, including basic operations like addition, checking positive or negative numbers, and looping. It also covers functions for calculating squares, finding the largest of two numbers, summing up to N, determining even or odd, calculating factorials, generating multiplication tables, and implementing bubble sort and linear search. Each example is presented with code snippets for practical understanding.

Uploaded by

arsalansial007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON COMPLETE NOTES (INPUT BASED PROGRAMS)

1. Addition Program
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print(a + b)

2. Positive or Negative
num = int(input("Enter number: "))
if num > 0:
print("Positive")
else:
print("Negative")

3. Loop (1 to n)
n = int(input("Enter number: "))
for i in range(1, n+1):
print(i)

4. Square using Function


def square(n):
return n*n

5. Largest of Two Numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print(max(a,b))

6. Sum of N Numbers
n = int(input("Enter number: "))
total = 0
for i in range(1,n+1):
total += i
print(total)

7. Even or Odd
n = int(input("Enter number: "))
if n % 2 == 0:
print("Even")
else:
print("Odd")

8. Factorial Program
n = int(input("Enter number: "))
fact = 1
for i in range(1,n+1):
fact *= i
print(fact)

9. Table Program
n = int(input("Enter number: "))
for i in range(1,11):
print(n, "x", i, "=", n*i)

10. Bubble Sort


arr = list(map(int, input("Enter elements: ").split()))
for i in range(len(arr)):
for j in range(len(arr)-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
print(arr)

11. Linear Search


arr = list(map(int, input("Enter elements: ").split()))
x = int(input("Enter search value: "))
found = False

You might also like