Professional Documents
Culture Documents
Python Questions 1
Python Questions 1
Numbers------------------------------------------
#N1. Find the lcm of two numbers
#N5. Check if a number is armstrong number ( Example : 153 = 1^3 + 5^3 + 3^3)
#N6. print all prime within a given range (Example :0-10 will print 2,3,5,7)
#N7. Compute prime factros of a integer (Example: prime factors of 60 are [2,3,5]
#N8. Check if a number input by user is divisible by only 2, only 3, both 2 and 3
or none
--------------------------------------
Strings-------------------------------------------
#s1. Replace all occurances of 'a' with '$' in a string (Example: car becomes c$r)
#s2. Detect if two string are anagrams (Example: 'jar' and 'raj' are anagrams)
#s3. Count the numbers of vowels in a string (Example: "Aware" will return 3)
#s4. Form a new string where the first charcater and the last character has been
exchanged
#s5. Remove the characters of odd index value in a string (Use slicing and step)
#s6. Calculate the number of words and the number of characters in a string
(Make sure to check for extra spaces)
#s8. Check if a string is palindrome (Example: civic, kayak will return yes)
#s9. Form a new string made of the first two and last two characters from a given
string
#L2. Write a Python program to print sum and multiply all the items in a list
#L3. Find the largest and smallest number in a list without using max and min
method
#L5. Sort in increasing order by the last element in each tuple from a given list
containg list with two integers. ( User defined functions knowledge will be
required)
Example: Input List [[2, 5], [2, 3], [4, 4], [1, 2], [2, 1]]
Output List[[2, 1], [1, 2], [2, 3], [4, 4], [2, 5]]
#L7. Write a Python program to convert a list of multiple integers into a single
integer.
Example : Input List: [1,2,3]
Output 123
Similarly input a number and form a list with all the digits as items in
list
Example : Input Number: 123
Output [1,2,3]
#L10. W.A.P. to add a list to a list without using append or insert or extend
method
Example: L1=[1,2,3]
L2=[4,5,6]
Hint(Use slicing to extend the list - Try playing around with it)
#L11. Create and print a list containing sqaures from 1 and user_input(Less than
50)
Example: Input : 5
Output : [1,4,9,16,25]
Input: 60
Output: Number out of range. Please reenter. To exit press y
Use Loop, conditonal checks and comparison operators
#D5. Create a dict with key as first character and value as words starting with
that character (Use split method for strings)
Example : User_input : "This is a good day"
Output : {'T':'This', 'i':'is, 'a':'a', 'g':'good', 'd':'day'}
#D6. Create a dictionary with squares of number as value and number as key
Example : Input : Enter a number:: 5
Output : {1:1, 2:4, 3:9, 4:16, 5:25}
----------------------------------------
Set--------------------------------------------
#Set1. Count the number of vowels present in a string using sets