Python assignment
Name: Muhammad Tanveer
Question No 01:
Write a Python program that takes a string input from the user, reverses it, and also counts
the number of vowels (a, e, i, o, u) in the original string.
# Question 1 Solution
# Taking input from the user
user_input = input("Enter a string: ")
# Reversing the string
reversed_string = user_input[::-1]
# Counting vowels
vowels = 'aeiouAEIOU'
vowel_count = sum(1 for char in user_input if char in vowels)
# Displaying results
print("Reversed String:", reversed_string)
print("Number of vowels in the original string:", vowel_count)
Question No 02:
Write a Python program that checks whether a given number is even or odd.
# Question 2 Solution
# Taking input from the user
number = int(input("Enter a number: "))
# Checking even or odd
if number % 2 == 0:
print("The number is Even.")
else:
print("The number is Odd.")
Question No 03:
Write a Python program using NumPy to sort the list.
# Question 3 Solution
import numpy as np
# Sample list
numbers = [12, 4, 56, 23, 9, 87]
# Converting to numpy array
np_array = [Link](numbers)
# Sorting the array
sorted_array = [Link](np_array)
# Displaying result
print("Original list:", numbers)
print("Sorted array:", sorted_array)