10 Python Assignment Programs (With Output)
Program 1: Hello World
Code:
print('Hello World')
Output:
Hello World
Program 2: Add Two Numbers
Code:
a=5
b=3
print(a+b)
Output:
8
Program 3: Even or Odd
Code:
n=4
if n%2==0:
print('Even')
else:
print('Odd')
Output:
Even
Program 4: Largest of Two Numbers
Code:
a=10
b=7
print(a if a>b else b)
Output:
10
Program 5: Factorial
Code:
n=5
f=1
for i in range(1,n+1):
f*=i
print(f)
Output:
120
Program 6: Print 1 to 5
Code:
for i in range(1,6):
print(i)
Output:
12345
Program 7: Sum of First 5 Numbers
Code:
s=0
for i in range(1,6):
s+=i
print(s)
Output:
15
Program 8: Positive or Negative
Code:
n=-2
print('Positive' if n>0 else 'Negative')
Output:
Negative
Program 9: Square of a Number
Code:
n=6
print(n*n)
Output:
36
Program 10: Simple Interest
Code:
p=1000
r=5
t=2
si=(p*r*t)/100
print(si)
Output:
100.0