0% found this document useful (0 votes)
24 views2 pages

Python Assignment 1

The document contains three Python programming assignments. The first program reverses a user-input string and counts its vowels, the second checks if a number is even or odd, and the third uses NumPy to sort a list of numbers. Each question includes a solution with code examples.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Python Assignment 1

The document contains three Python programming assignments. The first program reverses a user-input string and counts its vowels, the second checks if a number is even or odd, and the third uses NumPy to sort a list of numbers. Each question includes a solution with code examples.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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)

You might also like