0% found this document useful (0 votes)
16 views

PDF 2

The document contains 17 programming questions that involve taking user input, performing calculations, and displaying output. The questions cover a range of programming concepts like string manipulation, loops, conditional statements, lists, and more. Sample code and expected output is provided for each question to demonstrate how to solve the problems.

Uploaded by

VISHNU NAVEEN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

PDF 2

The document contains 17 programming questions that involve taking user input, performing calculations, and displaying output. The questions cover a range of programming concepts like string manipulation, loops, conditional statements, lists, and more. Sample code and expected output is provided for each question to demonstrate how to solve the problems.

Uploaded by

VISHNU NAVEEN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

QUESTIONS

1. Write a program to take a string from the user and display


its length and also display the string after converting into
uppercase.

Input:

x = input("Enter the string: ")


print(len(x))
print(x.upper( ))

Output:

Enter the string: vyom


5
VYOM

2. Write a program to take 2 numbers from user and display


its quotient, remainder, dividend and divisor in a
formatted way.

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:

Enter the Dividend:7


Enter the Divisor:6
7 Dividend
6 Divisor
1 Remainder
1.1666666666666667 Quotient
3. Write a program to take a number from user and display
its table in a dodging way.

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:

number = int(input("Please Enter any Number: "))

i = number

print("List of Natural Numbers from {0} to 1 in Reverse


Order".format(number))

while ( i >= 1):

print (i, end = ' ')

i = i-1

Output::

Please Enter any Number: 6

List of Natural Numbers from 6 to 1 in Reverse Order

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

7. Q.8. Write a program to print the pyramid.


1
23
456
7 8 9 10

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

9. Write a program to print the pyramid of capital letters.


A
AB
ABC
ABCD

Input:

# outer loop for ith rows


for i in range (65,70):
# inner loop for jth columns
for j in range(65,i+1):
print(chr(i),end="")
print()

Output:

A
BB
CCC
DDDD
EEEEE

10. Write a program read a number from user and check


whether its prime number or not.

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:

n = int(input("Enter the number"))


i=1
while(i<=n):
if i%2==0:
print(i)
i=i+1

Output:

All the even numbers from 1 to 100(inclusive)

12. Write a program to take a number and name from user


and check whether it’s a palindrome.

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

13. Write a program to perform the following and display:


i) length of the list
ii)display in alphabetic order
iii)display max
iv) display min
v)add one element at the at the second position

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

14. Display Fibonacci series.


0,1,1,2,3,5,8,13,21……

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

17. Write a program to read a string and display the total


number of of lower-case and upper case and vowels present in
the string.

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:

Enter a String Vishnu

Vowels 2

Uppercase 1

Lowercase 5

You might also like