Questions For Python
Questions For Python
1. Write a Python program which accepts a sequence of comma-separated numbers from user and
generate a list and a tuple with those numbers.
1. Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn
1. Write a Python program to get the difference between a given number and 17, if the number is greater
than 17 return double the absolute difference.
1. Write a Python program to test whether a number is within 100 of 1000 or 2000.
1. Write a Python program to calculate the sum of three given numbers, if the values are equal then return
three times of their sum.
1. Write a Python program to get a new string from a given string where "Is" has been added to the front. If
the given string already begins with "Is" then return the string unchanged.
1. Write a Python program to find whether a given number (accept from the user) is even or odd, print out
an appropriate message to the user.
1. Write a Python program to concatenate all elements in a list into a string and return it.
1. Write a Python program to compute the greatest common divisor (GCD) of two positive integers.
1. Write a Python program to get the least common multiple (LCM) of two positive integers.
1. Write a Python program to sum of two given integers. However, if the sum is between 15 to 20 it will
return 20
1. Write a Python program that will return true if the two given integer values are equal or their sum or
difference is 5
1. Write a Python program to take the user information for n students details like name, age, address and
print them on different lines.
1. Write a Python program to find the sum of array (hint take a list as array).
1. Write a Python program to imitate bank transactions like deposit, withdrawal and check balance.
1. Write a Python program to imitate login activity of a user also do its validation. (hint:-If user enters the
wrong userid or password it should provide a message)
1. Write a Python program to imitate a shopping transaction where user purchase 5 notebooks of 20 rs
each and 2 pens of 5 rs each. Show the total amount to be payable to the shopkeeper.
1. Accept the age of the person and print an appropriate message as per the table given alongside:
Age Message
<=12 You are child
13-19 You are a teenager
20-59 You are an adult
>= 60 You are a senior citizen
1. Accept the purchases made by a customer and calculate and print the discount payable by him. You are
given that a discount of 10% is given on purchases greater than Rs. 3000/- and no discount is given for
purchases below that.
1. Accept the gross salary of an employee. Calculate and print the tax based on the given criteria.
1. Accept the quantity of an item purchased and its price. Calculate the amount of purchase. If the amount
exceeds Rs.5000, a discount of 20% is given otherwise the discount rate is 10%. Print the input values,
the discount rate and amount, net amount to be paid by the customer.
1. Accept the marks obtained by the 5 students for subjects of Python, Statistics, Machine Learning, Deep
Learning, Big-Data also all marks are out of 100. Find the sum and percentage of the for all students and
display the name and marks of the first rank holder.
1. Given 2 int arrays, a and b, each length 3, return a new array length 2 containing their middle elements.
1. Given an array of ints, return a new array length 2 containing the first and last elements from the original
array. The original array will be length 1 or more.
1. Write a Python program to find the Mean, Median and Mode of three user entered values
1. Write a Python program to check the validity of password input by users. Go to the editor Validation:
1. Write a program to find the largest of two numbers without using function.
1. Write a program to find the largest of three numbers without using functions.
1. Write a program to find the average of 10 numbers entered from the user.
1. Write a program to find even and odd numbers from the given list
1. Write a program to append elements of various datatypes (total three elements 1 integer, 1 float and 1
string)
1. Write a program to illustrate the difference between append and extend functions in list.
1. Write a program to reverse a string input should be taken from the user.
1. Write a program to reverse a number input should be taken from the user.
1. Write a program using functions to create a calculator (only +, -, * and /) operations should be performed.
1. Write a program to add all the elements in the list without using inbuilt function.
1. Write a program to take two lists from the user and add the element present at same index from two list
and create a third list. for e.g. element at index 1 of list 1 should get added with element at index 1 of list
2 and so on.
1. Write a program to get the prime no up to n. n should be taken from the user.
1. Write a program to find sum of first n natural no value of n should be taken from the user.
1. Write a program to calculate area of various shapes like circle, rectangle and square using function.
1. Write a program to calculate Simple Interest using function. Take the values from the user for P, N, and
R.
1. Write a program to calculate Compound Interest using function. Take the required parameter from the
user.
1. Write a program to take the paise value from the user and convert it into rupee.
1. Write a program to take a list from the user and find the cube and square root of every number in it.
1. Write a Python program to find those numbers which are divisible by 7 and multiple of 5, between 1500
and 2700 (both included).
1. Write a Python program to convert temperatures to and from celsius, fahrenheit. [ Formula : c/5 = f-32/9 [
where c = temperature in celsius and f = temperature in fahrenheit ].
1. Write a Python program that accepts a word from the user and reverse it.
1. Write a Python program to construct the following pattern, using a nested loop number.
1. Accept a character from the user and check for the following and display appropriate messages:
2. Is the character a vowel or consonant?
3. Is the character in uppercase or lowercase?
4. Does the character occur in the string “Data Science” and if so at what position?
1. Write a program to show the use of various arithmetic operators using if ..elif..else.
1. Given below is the list of marks obtained by a class of 50 students in an annual examination. 43 65 51
27 79 11 56 61 82 09 25 36 07 49 55 63 74 81 49 37 40 49 16 75 87 91 33 24 58 78 65 56 76 67 45 54
36 63 12 21 73 49 51 19 39 49 68 93 85 59 Write a program to count the number of students belonging
to each of following groups of marks: 0-9, 10-19, 20-29,.....,100.
1. Write a program to sort a list and then find the median from it.
1. Write a program to find the second highest value from the list.
1. Take three list from user first list is of gender second list of height and third list of weight for 15 students
and then perform following things
1. Write a program to read a sentence from the user in any case and convert it into upper case.
1. Write a program to read a sentence from the user in any case and convert it into lower case.
1. A computer manufacturing company has the following monthly compensation policy to their
salespersons: Minimum base salary : 1500.00 Bonus for every computer sold : 200.00 Commission on
the total monthly sales : 2 per cent Since the prices of computers are changing, the sales price of each
computer is fixed at the beginning of every month.
1. Write a program to evaluate the equation s=sqrt(a()+b()) using functions(Where a() and b() are function
which perform some task )
1. Write a program to take a sentence from the user and then find count of elements in the sentence. (hint:
that is calculate how many alphabets how many whitespaces etc.are present)
1. Write a program to take 5 names in the list and sort that list in ascending and descending orders and
store the output in two different list.
1. Write a program to copy one string into another and count the number of characters copied.
1. Write a program to identify the profit and loss in an organization assume your own suitable data.
1. Write a program which take a string from the user and decrypt it using shift by 3 method (hint: if user
enters the value C it should be encrypted as A and so on.)
1. Write a program to calculate standard deviation and variance. Assume the data in the list.
def bs(a):
b=len(a)-1
for x in range(b): for y in range(b-x): if a[y]>a[y+1]: a[y],a[y+1]=a[y+1],a[y] return a
</pre>
</pre>
1. A. Write a Python program calculate the salary of an employee by using salary equals to basic salary +
H R A minus Income Tax assume that employees are categorised into 2 grade 1 and Grade 2 if the
employees belong to grade 1 hr calculated 15% basic salary and calculate 30% basic salary if the
employee belong to read 2001 calculated 10% basic salary and calculated 25% of basic salary and
for both grade employees income tax will be calculated as 5% of basic salary
1. Write a Python function that accepts student names and marks (store in list). Calculate the total marks
and average based on the input. Display student names and marks, total and average.
1. Given the value of length, print the X pattern in a box using # and ” ” based on the input as given below
1. What Is The Result Of The Below Lines Of Code?Here is the example code.
1. How Would You Produce A List With Unique Elements From A List With Duplicate Elements? Example :-
This is the list ['a','b','c','d','d','d','e','a','b','f','g','g','h',i,k,k,p]
1. Give the output of the given sinpet and explain the code.
1. Write a program to delete each element in the list which is divisible by 2 or all the even numbers.
example: - list1 = [11,5,17,4,18,23,50,10]
1. Write a program to convert a list of multiple integers into a single integer Example where input is [1 ,2 ,3]
and output is [123]
1. Write a program to count the number of each vowel in a string using dictionary and list comprehension.
1. Write a program to remove all the punctuations from a string and check each character of the string
using for loop, If the character is a punctuation, assign an empty string to it.
1. Write a python program to find the second largest number in a list and explain the steps.