# Python practice programs

Difficulty | Low | Medium | High |
---|

## [Python Introduction]

### 1. Who is the inventor of python language?

A. Monte Python B. Guido Van Rossum C. Larry Wall D. David H. Hansson

### 2. Which is not a features of python programming?

A. Object-oriented B. Interactive C. Interpreted D. Statically typed

### 3. Which function is used to retrieve the data type of a variable or object?

A. type() B. dtype() C. dir() D. help()

### 4. Which function is used to list attributes of a given object?

A. type() B. dtype() C. dir() D. help()

### 5. Which is not a keyword in python3?

A. def B. while C. print D. elif

### 6. Which keyword in used get other modules in python code?

A. import B. include C. inherit D. install

### 7. Which of the following will be invalid python variable name?

A. abc123 B. _abc123 C. abc_123 D. 123_abc

### 8. Which is not correct data declaration in python?

A. x = -19.8 B. x = 1+2j C. x, y = 1, 2 D. x, y, z = 1

### 9. Which of them will be False?

A. "hello" == 'hello' B. 'a' == 'A' C. 5 in [3, 4, 5] D. 'a' not in "AEIOU"

### 10. Which of the following statement is incorrect?

A. var = "hello"; B. var = "hello " + "world" C. var = 'I can't learn python' D. a = 1; b = 2

## [Python Functions]

### 11. WAP to add two integers, floating point and complex numbers.

>>> practiceQuestion(2, 4) 6 >>> practiceQuestion(-2, 1.5) -0.5 >>> practiceQuestion(1+2j, 3+4j) (4+6j)

### 12. WAP to find the area of a square with given side length.

>>> practiceQuestion(30) 900

### 13. WAP to find the BMI (body mass index) for weight in kg and height in meter.

**Formula : BMI is weight in kg divided by square height in meter.**

>>> practiceQuestion(67, 1.67) 24.02

### 14. WAP to convert temperature from Celsius to Fahrenheit scale.

**oC to oF Conversion: Multipy celcius by 9, then divide by 5, then add 32.**

>>> practiceQuestio(28.0) 82.40

### 15. WAP to find hypotenuse of a right angled triangle using Pythagorous theorem.

**Formula: hypotenuse is the sqruare root of square base plus square height.**

Hint: import math; math.sqrt() >>> practiceQuestion(3, 4) 5.0

### 16. WAP to find the area of a half circle using the given radius.

**Area of circle: pi*r**2**

Hint: import math; math.pi

Hint: import math; math.pi

>>> practiceQuestion(3) 14.14

### 17. WAP to find the maximun, minimum and sum from a given list of numbers.

**Hint: Use built-in functions max(), min() and sum()**

>>> practiceQuestion([1, 6, 3, 4, 5]) (6, 1, 19)

### 18. WAP to the ascii order of a given character.

**Hint: User builtin function ord()**

>>> practiceQuestion('A') 65 >>> practiceQuestion('a') 97

### 19. WAP to find the the discriminant of a quadratic equation ax^2+bx+c.

**Formula: Discriminat is b**2-4ac**

>>> practiceQuestion(1, 3, 2) # in the order of (a, b, c) 1 >>> practiceQuestion(1, 4, 4) 0 >>> practiceQuestion(1, 2, 3) -8

### 20. WAP to find the distance between two points on the graph with their co-ordinates as (x1, y1) and (x2, y2).

**Formula: distance is the square root of square difference of x co-ordinates, plus square difference of y co-ordinates.**

>>> practiceQuestion(1, 1, 4, 5) # in the order x1, y1, x2, y2 5.0

## [Python Conditions]

### 21. WAP to check if a given number is positive and even.

>>> practiceQuestion(20) True >>> practiceQuestion(-2) False >>> practiceQuestion(3) False

### 22. WAP to check if a given number is divisible by 7 or 11.

>>> practiceQuestion(21) True >>> practiceQuestion(22) True >>> practiceQuestion(23) False

### 23. WAP to check if a given number can represent a leap year.

>>> practiceQuestion(120) True >>> practiceQuestion(123) False >>> practiceQuestion(200) False

### 24. WAP to check if a given number is Prime.

>>> practiceQuestion(17) True >>> practiceQuestion(9) False >>> practiceQuestion(-2) False

### 25. WAP to check if three given number can represent sides of equilateral triangle.

>>> practiceQuestion(2, 2, 2) True >>> practiceQuestion(-3, -3, -3) False >>> practiceQuestion(2, 3, 2) False

### 26. WAP to check if three given number can represent sides of isosceles triangle.

>>> practiceQuestion(2, 2, 1) False >>> practiceQuestion(-3, 1, -3) False >>> practiceQuestion(2, 3, 2) True

### 27. WAP to check if three given number can represent sides of scalene triangle.

>>> practiceQuestion(2, 2, 2) False >>> practiceQuestion(3, 4, 5) True >>> practiceQuestion(2, 3, 2) False

### 28. WAP to return "Fizz" if the given number is divisible by 3, "Buzz" if it is divisble by 5, "FizzBuzz" if it is divisble by both and the same number if it is divisible by none.

>>> practiceQuestion(6) Fizz >>> practiceQuestion(15) FizzBuzz >>> practiceQuestion(7) 7

### 29. For a quadratic equation in the form of ax2 + bx + c, the discriminant, D is b2-4ac. Write a function that return the following output depending on the discriminant.

D > 0: 2 real roots; D = 0: 1 real root; D < 0: 2 complex roots >>> practiceQuestion (1, 2, 3) 'This equation has 2 complex roots' >>> practiceQuestion(1, 3, 2) 'This equation has 2 real roots' >>> practiceQuestion(1, 4, 4) 'This equation has 1 real root'

### 30. Write a function that converts the time from military to regular format.

>>> practiceQuestion('1619') '4:19 pm' >>> practiceQuestion('1200') '12:00 pm' >>> practiceQuestion('1020') '10:20 am'

### 31. WAP to filter all vowels in a given string.

>>> practiceQuestion('Apple') 'Ae'

### 32. WAP to filter out all odd numbers from a list of numbers.

>>> practiceQuestion([234,52,345,34,53]) [234, 52, 34]

### 33. WAP to print the index of all odd numbers.

>>> practiceQuestion([234,52,345,34,53]) 2 4

### 34. WAP to delete all vowels from a string.

>>> practiceQuestion("Apple") ppl

### 35. WAP to check if a given string has same consecutive vowels.

>>> practiceQuestion('school') True >>> practiceQuestion('Apple') False

### 36. WAP to check if a given number is prime.

>>> practiceQuestion(17) Prime >>> practiceQuestion(-2) Non-prime

### 37. WAP to get the sum of first digits from a list of numbers.

>>> practiceQuestion([1, 20, 300, 4005]) 10

### 38. WAP to check if a given password has a mix of letters and digits.

>>> practiceQuestion('abc12ed') True >>> practiceQuestion('abcd') False >>> practiceQuestion('1234') False

### 39. WAP to get the list of numbers beween two give numbers (inclusive).

>>> practiceQuestion(2, 7) [2, 3, 4, 5, 6, 7]

### 40. WAP to print "hello" until 'Y' is pressed as input else stop.

>>> Enter choice: Y hello >>> Enter choice: N

### 41. WAP to add a given value in the beginning of a given list.

Enter list: [1, 2, 3] Enter value: 100 [100, 1, 2, 3]

### 42. WAP to delete the first and last values from a list.

>>> practiceQuestion([]) [] >>> practiceQuestion([1]) [] >>> practiceQuestion([1, 2, 3, 4]) [2, 3]

### 43. WAP to add the first and last value from a list.

>>> practiceQuestion([]) 0 >>> practiceQuestion([17]) 17 >>> practiceQuestion([1, 2, 3, 4]) 5

### 44. WAP to delete all odd numbers from a list of numbers.

>>> practiceQuestion([2, 45, 56, 67, 69, 12, 13, 15]) [2, 56, 12]

### 45. WAP to get the common and sorted data in two lists.

>>> practiceQuestion([1, 2, 7, 3], [4, 3, 7]) [3, 7]

### 46. WAP to join the list of words as a sentance in capital case.

>>> practiceQuestion(['i', 'SOLVED', 'PYthon', 'practice', 'QUEStions']) I solved python practice questions

### 47. WAP to sort and reverse a given list.

>>> practiceQuestion([34, 12, 45]) [45, 34, 12]

### 48. WAP to get the sum of list values.

Enter a list: [1, 2, 3, 4, 5] 15

### 49. WAP to get the maximum and mininum values from a list of numbers.

>>> practiceQuestion(Enter a list: [32,52,35,234,5,2345,234,5234,2]) 5234 2

### 50. WAP to find the sorted uncommon values in two lists.

>>> practiceQuestion([1, 2, 3, 4], [3, 4, 6, 5]) [1, 2, 5, 6]