Python practice
Question 1: Reversing a String
Write a Python function to reverse a given string.
The string is “I am learning Python”
- Create a function for reversing the string
- The name of the function should be “reverse_string”
solution -
Question 2: Finding Prime Numbers
Write a Python function to generate a list of prime numbers up to a given number n.
1.Create a function named generate_prime which will take an input of numbers
2.Find prime no till 20
solution :
Question 3: Calculating Factorial
Write a Python function to calculate the factorial of a given non-negative integer.
- If someone tries to find the factorial of 0 & 1 it should return 1 to the user The function name should be “factorial” taking an input parameter “n”
solution :
Question 4: Counting Words in a Sentence
Write a Python function to count the number of words in a given sentence.
1.It should count the words in a sentence
2.The function name is count_words taking
solution:
Question 5: Finding Maximum Element
Write a Python function to find the maximum element in a list.
example :- List of no is [ 10 , 5 , 20 , 3, 2, 8, 20 , 2]
1.If the list is empty it should return None
2.Create function with name find_max_element
solution :