PDF 2
PDF 2
Input:
Output:
Input:
x = int(input("Enter the Dividend:"))
y = int(input("Enter the Divisor:"))
print(x, "Dividend")
print(y, "Divisor")
print(x%y, "Remainder")
print(x/y,"Quotient")
Output:
Input:
x = int(input("Enter a Number:"))
for i in range(1,11):
s = x*i
print(x,"*",i,"=",s)
Output:
Enter a Number: 47
47 * 1 = 47
47 * 2 = 94
47 * 3 = 141
47 * 4 = 188
47 * 5 = 235
47 * 6 = 282
47 * 7 = 329
47 * 8 = 376
47 * 9 = 423
47 * 10 = 470
4. Write a program to display the first natural 100 numbers
in reverse order.
Input:
i = number
i = i-1
Output::
654321
5. Swap two numbers without using third variable.
Input:
x,y = 3,5
x,y = y,x
print(x,y)
Output:
5,3
6. Write a program to print the pyramid.
1
22
333
4444
55555
Input:
for i in range(1,6):
for j in range(1,i+1):
print(i,end=" ")
print()
Output:
1
22
333
4444
55555
Input:
k=1
for i in range(1,5):
for j in range(1,i+1):
print(k,end=" ")
k+=1
print()
Output:
1
23
456
7 8 9 10
8. Q.9. Write a program to print the pyramid of small letters.
a
bb
ccc
dddd
Input:
a = 97
n=4
for i in range(1,n+1):
for j in range(1, i+1):
print("%c" %(a), end="")
a +=1
print()
Output:
a
bb
ccc
dddd
Input:
Output:
A
BB
CCC
DDDD
EEEEE
Input:
n = int(input("Enter a Number:"))
count=0
i=1
while(i<=n):
if (n%i==0):
count = count + 1
i = i+1
if (count==2):
print("Yayy, It is a prime number")
else:
print("Oops, It is a composite number")
Output:
Enter a Number: 7
Yayy, It is a prime number
11. Display all the even numbers from 1 to 100 both the
number are inclusive.
Input:
Output:
Input:
def palin(n):
rev=0
z=n
while(z>0):
rev=rev*10 +z%10
z = z//10
print("Reverse=",rev)
if(rev==n):
return 1
else:
return 0
n = int(input("Enter a Number:"))
val = palin(n)
if (val==1):
print("It is a palindrome")
else:
print("It is not a palindrome")
a = input("Enter a string")
b = a[-1::-1]
if(a==b):
print("It is a palindrome string")
else:
print("It is not palindrome string")
Output:
Enter a Number:787
Reverse= 787
It is a palindrome
Enter a string Vishnu
It is not palindrome string
Input:
a = ['Ronaldo','Messi','neymar','lewandowski']
print(len(a))
print(max(a))
print(min(a))
print(a.insert(2,'Mbappe'))
Output:
4
neymar
Messi
None
Input:
n= int(input("Enter a number"))
x=0
y=1
z=0
while(z<=n):
print(z)
x=y
y=z
z=x+y
Output:
Enter a number 9
0
1
1
2
3
5
8
15. Write a program to take a number from the user and display
its factorial.
Input:
i = int(input("Enter a Number"))
fac=1
while(i>0):
fac=fac*i
i = i-1
print("Factorial",fac)
Output:
Enter a Number 7
Factorial 5040
16. Write a program to take a number from the user and display
its factor.
Input:
a = int(input("Enter a Number"))
i=1
while i<=a:
if a%i==0:
print(i)
i+=1
Output:
Enter a Number 8: 1,2,4,8
Input:
a = input("Enter a String")
vowels = 0
uppercase = 0
lowercase = 0
for i in range(0,len(a)):
if (a[i].isupper()):
uppercase=uppercase+1
for i in range(0,len(a)):
if (a[i].islower()):
lowercase = lowercase+1
for i in range(0,len(a)):
if(a[i] =='a' or a[i] == 'e' or a[i] == 'i' or a[i] == 'o' or a[i]== 'u'):
vowels = vowels +1
print("Vowels",vowels)
print("Uppercase",uppercase)
print("Lowercase", lowercase)
Output:
Vowels 2
Uppercase 1
Lowercase 5