0% found this document useful (0 votes)
23 views14 pages

Python Questions

Uploaded by

jimpakchimpak007
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)
23 views14 pages

Python Questions

Uploaded by

jimpakchimpak007
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
You are on page 1/ 14

If programs:

1. Write a program using the if condition.


Note: Pass true as a boolean value as input in if condition.
Output: Should display If block is executed.

2. Write a program using IF condition.


note: Pass 1 as input in if condition.
Output: Should display If block of code is executed.

3.Write a program to print the given number as a Positive Value.


Input: 2
Output: Given Value is Positive.

4.Write a program to print the given number as an Even Number .

Input:6
Output: Given Number is Even

5. Write a program to print the given number as an Odd Number.


Input : 3
Output: Given Number is Odd

6.Write a program to print the person's age as Major/Minor.


Input: 18
Output: Major

7.Write a program to check that both the values are the same?
Input: 20 && 20
Output: Numbers are equal

8.Write a program to compare if both values are equal or not?


Input: "abc" && "abc"
Output: Strings are equal

9. Write a program using multiple If conditions to check greater than/less than/Equal to


condition among 2 values.
Input: a=10, b=15
Output: a less than b

10. Write a program to check the percentage among 3 subjects.


input : 80,80,80
output: 80

if-else program:
11. Write a program to check whether the given number is even or odd?

Input: 2 Output: Given number is Even

Input :3 Output: Given number is odd

12. Write a program with these values in if condition


1. If we pass 1 print true value.
2. If it is 0 print false value.

13. Write a program to check whether the given number is positive or negative?

Input: 2 Output: Given number is positive

Input : -3 Output: Given number is negative

14. Write a program to check whether the student is pass or fail based on marks given?

Input: 35 Output: Pass

Input: 34 Output: Fail

15. Write a program to check whether the given year is a leap year or not?

Input:2004 Output: Given year is leap year

Input:2003 Output: Given year is not a leap year.

16. Write a program using && in if condition, check the given number is divisible by 3 & 5.

Input: 15 Output: 15 is divisible by 3 & 5

Input: 18 Output: 18 is not divisible by 3 & 5.

17. Write a program to check the given alphabet is Vowel or consonant?

Input: a Output: A is Vowel

Input : c Output: C is consonant

18. Write a program to check the given person's age is major or minor?

Input: 18 Output: Given person age is major

Input:17 Output: Given age is minor

19. Write a program to check whether the given letter is in Uppercase/Lowercase?

Input: A Output: A is in Uppercase


Input: b Output : b is in lowercase.

20. Write a program to calculate profit or loss?

Input: Cost of product : 1000, Spelling Price: 1500

Output: Profit is 500

If-else ladder:

21. write program to check whether a character is alphabet, digit or special character

input : hello
output : string
input : 978
output : Number
input : @
output : special character

22. write a program to check the maximum number among 3 numbers

input : a=20;b=30,c=35
output : c is maximum value

input: a = 10; b= 43; c=34


output : b is maximum value

input : a= 45;b =33; c = 21;


output : a is maximum value

23. Program to print days in a month using logical OR operator

input : 1
output : 31 days like that;

24 .Write a program to input marks of five subjects Physics, Chemistry,


Biology, Mathematics and Computer. Calculate percentage and grade
according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
25. Write a C program to input the basic salary of an employee and calculate gross
salary according to given conditions.
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary is between 10001 to 20000 : HRA = 25%, DA = 90%
Basic Salary >= 20001 : HRA = 30%, DA = 95%

input : basic salary of employee : 22000


output : gross salary : 44000

26 . Write a program to enter week number and print day of week?


Take numbers from 1 to 7
Input : 3
Output : Tuesday
Input : 8
27. Print the metro stations based on ticket cost?
Input: Rs 10 Output: miyapur to jntu
Input: Rs 20 Output: miyapur to kukatpally
Input: Rs 30 Output: miyapur to bharat nagar
Input: Rs 65 Output: ticket cost is up to Rs 60 .
28. Print bike model based on bike mileages?
Input : 60 Output: Grammar
Input: 40 Output: Unicorn
Input: 34 Output: Royal Enfield
Input: 80 Output: Bajaj CT100
29. Write a program to print wishes based on time ?
Input : < 12
Output : Good morning
Input : > 12 and < 18
Output : Good after noon
Input : > 18 and < 24
Output : Good night

30. Program to check equilateral, scalene or isosceles triangle


input : side 1 : 60
side 2 : 60
side 3 : 60

output : equilateral triangle

input : side 1 : 90
side 2 : 45
side 3 : 45

output : isosceles triangle

input : side 1 : 40
side 2 : 50
side 3 : 90

output : scalene triangle

Nested-if:

31. Write a program to take user name and password and print username and
password are correct or not
Static data:
Username : ‘a’
Password: 123

Input:
User name: a Output: Login successfully
Password: 123
Input:
User name : a Output: Password is incorrect try again
Password: 1234
Input:
Username: b Output: User name is incorrect try again
Password: 123

32.Print the biggest number among 4 numbers?


Input : a=10;b=25;c=30;d=5; Output: “C” is the
big number.

33.print the given vowel is small letter (or) capital letter?


Input: a Output: small letter
Input: A Output:capital letter
Input:b Output: consonant

34.print the person is eligible for government job (Or) not?(based on age)
Input: age=17
Output: your age is below to work

Input:
age=25 Output
: your eligible for work

Input:
age=60 Output
: Your eligible to take pension.

35. Print the boy and girl is eligible for marriage?


Input: boy=18; girl=18 Output: both are eligible for marriage
Input: boy=18; girl=17 Output: boy is eligible for marriage
Input: boy=17;girl=18 Output: girl is eligible for marriage.
Input: boy=17;girl=17 Output:boy and girl is not eligible for
marriage
36.print the given number is even (Or) odd?
Input: 5 Output: odd number
Input:6 Output:even number
Input: a Output: not a number

37.print the person is eligible for donation of blood?(based on age and weight)
Input: age=18 and weight=50 Output: eligible for donation of blood
Input:age=18 and weight=48 Output:your weight is
low so your not eligible for donation of blood.
Input: age=17 and weigh=52 Output: your age is
below to donate blood

38.Print the true only when given inputs values and types are
matched?
Input: a=10;b=10 Output: true
Input: a=10 ; b=”10” Output: false

Switch

41.write a program to print as below format?

Input: 1 Output: the number is 1

Input:2 Output: the number is 2

Input:3 Output: the number is 3

Input:5 Output: the value is more than 3.

42.Write a program to print a given letter as a vowel or consonant?

Input: a or A Output: Vowel

Input: b or B Output: Consonant

43.Write a program to print week days by using numbers (days should start
from 0 index number)?
Input: 1 Output: Monday

Input: 7 above Output: invalid day

44.Write a program to find how many days in months(if feb is leap year print 29
days)

Input: 2018 jan Output: 31 days

Input: 2018 feb Output: 28 days

45. Write a program to print operation between two numbers regarding


operands?(simple calculator)

Input: 2 + 2 Output: 4

Input: 2 – 2 Output: 0

input : 2 * 2 output : 4

input : 2/2 output : 1


46.Write a program to print travel in the metro from where to where regarding
ticket cost?

Input: 15 Output: Miyapur to Jntu

Input: 45 Output: Miyapur to Ameerpet

Input: 65 Output: Please check ticket costs

47.write a program to print the gender is male or female?

Input: m Output: male

Input:F Output: female

Input: g Output: undefined.

48.write a program to print the percentage and grade of a student.(of 5


subjects)

Input: 90,90,90,90,90 Output: 90 percentage and “A” grade

Input:40,40,40,40,40 Output: 40 percentage and improve the


study

49.write a program to print the cost of a fruits?


Input: banana Output: cost 5

Input: apple Output: cost 10


50. write a program to print the cost a laptop?

Input: hp Output:35k

Input: dell Output:40k

For loop:

51.write a program to print 1 to 10 numbers ?


52.write a program to print 1 to n numbers ?
53.write a program to print 1 to n even numbers and odd numbers ?
54.write a program to print sum of 1 to n even numbers and odd numbers?
55.write a program to print sum of n even numbers?
56.write a program to print if a given number is prime or not ?

input : 3

output : given number is prime number

57. write a program to print 1 to n prime numbers ?

input : n = 10;

output : 2,3,5,7

58. write a program to print n prime numbers ?

input : n = 10;

output : 2,3,5,7,11,13,17,19,23,29
59. Write a program to print given number is perfect number or not?

Input : 28 output : given number is perfect number

60. Write a program print ⭐ in the below patter?


Input :4

Output : ****
****
****
****
While:

61. Write a program to print numbers in reverse order 1 to n numbers?


input: 5 ; output : 5,4,3,2,1

62. Write a program to print factorial value based on given number?


input : 4 output : 24
63.Write a program to print the table based on given number?

64. Write a program to print the tables upto given number?


65.Write a program to print fibrosis series?

Enter the number : 10


Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34

66.write a program to check whether the given number is Armstrong number or not
[Note : input number must only be 3 digits?]
input : 153 output : Armstrong number
input : 152 output : Not Armstrong number

67. print the star in the pattern below?

input : 5

output :*
**
***
****
*****
****
***
**
*
68 write a program to print triangle?

Input: 4 Output : *
**
***
****

69. Write a program to print Strong numbers?

A strong number is a number if the factorial of its digit is equal to the number itself.
Eg: 145 is a strong number. Factorial of 145 is 1! + 4! + 5! = 1 + 24 + 120 = 145

70. Write a program to print squares?


Do-while:

71. print the 1 to n prime numbers


72. print the number in below order
input ; 5 output : 11111
00000
11111
00000
11111

73 print the number in below order


input : 5 output : 01010
01010
01010
01010
01010
74. Write a program to print exponential values based on base and exponential ?

input: base : 2 expo : 3 output : 8 like that

75. Write a program to print sum of first number and last number

Input: 1234 output: 5


76 . write a program to print the given number in reverse order ?

Note : don't use the string data type

input : 456 output : 654

77. write a program to print given number is palindrome number are not ?

input : 121 output : given input is palindrome number

78. write a program to print the pattern below ?

input: 5 output : 1
21
321
4321
54321

79. write a program to print the pattern below ?

input : 5 output :
1 1
2 2
3 3
4 4
5
4 4
3 3
2 2
1 1
1
21
Note : use input as odd number only to get star pattern
80. write a program to print like that ?

input : 10

output :
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100

Arrays:

81.Write a program to print array elements.

Suppose take one Array a[]={1,2,3,4,5,6,7};(Take Array elements


Dynamically.)

Just print that Array elements.

Output:1 2 3 4 5 6 7.

82.Write a program to print even numbers and odd numbers in an array?

Suppose take one Array a[]={1,2,3,4,5,6,7};(Take Array elements


Dynamically.)

Output:

Even numbers are: 2, 4, 6

Odd numbers are: 1, 3, 5, 7

83.Write a program to print array elements in reverse order?

Suppose take one Array a[]={1,2,3,4,5,6,7};(Take Array elements


Dynamically.)

Output: 7, 6, 5, 4, 3, 2, 1
84. Write a program to print array elements in ascending order in a for loop by using
functions.

input :Array[]={3,1,8,45,2,90,7,12,5};(Take Array elements Dynamically.)

Output:Ascending order is:1,2,3,5,7,8,12,45,90.

85. Write a program to print array elements in descending order in for loop by using
functions.

input :Array[]={3,1,8,45,2,90,7,12,5};(Take Array elements Dynamically.)

Output: Descending order is:90,45,12,8,7,5,3,2,1

86. Write a program to find the minimum and maximum elements in an array in a for loop
by using functions.

input :Array[]={3,1,8,45,2,90,7,12,5};(Take Array elements Dynamically.)

Output:

Minimum element of an Array is:1

Maximum element of an Array is:90.


87.Write a program to find Duplicate elements in an array in for loop by
using functions.
input :Array[]={3,4,5,6,7,2,2,1,10,12,10,15,16,17,3,3};

output: Duplicate elements are:3,2,10

88.Write a program to find Common elements between two arrays of


integers in for loop by using functions.
input :Array1[]={1,2,3,4,5,6,7,8,9,3,5,6,90};
Array2[]={5,3,12,34,90,5,1,2,4};

Output: Common elements between two arrays:1,2,3,4,5,90

89.write a program to print common elements between two arrays(in Strings)

Input:
arr1=["cat","bat","rat"]

arr2=["hat","rat","sweet"]

OUTPUT:

common elements between two arrays:rat

90.write a program to merge two array elements


Input:

arr1=[10,20,30]

arr2=[40,50,60]

output:

arr=[10,20,30,40,50,60]

91.write a program to print non repeated array elements

Input:

arr1=[1,2,3,1,5]

output:

Non Repeated array elements are :2,3,5


92. write a programs to print the missing elements in the given range in an array ?

Input : Range 1 to 25

input : 2,5,8,1,4,7,22,25,23

Output : Missing elements are : 1,3,4,6,9,10,11,12,13,14,15,16,17,18,19,20,21,24.

93. write a program to print first and second non repeated array elements ?

Input : 2,3,3,5,6,5

Output : First non repeated element :2


second non -repeated element :6

94.write a program to print and find the length of A STRING in a given array ?

input : ["html","css","javascript","node"]

output : html - 4
css -3
javascript - 9
node - 4

95. write a program to print string elements of an array in ascending order(based on


length of a string) in a given array ?

input : ["html","css","javascript","node"]

output : css,html,node,javascript
97.write a program to print reverse the string in an given array ?
input : [java,HTML]

output: [avaj,LMTH]

98.write a program to print left rotate of an array values ?

input : original Array values are :2,9,3,4,7


input : left rotate : 2
output : 3,4,7,2,9
99.Write a program to print ascending order of even and odd elemnets of
an array in for loop by using functions.

input :Array[]={3,1,8,45,2,90,7,12,5};(Take Array elements


Dynamically.)

Output:

Even elements are:2,8,12,90

Odd elements are:1,3,5,7,45

You might also like