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

Python Programming Assignment 01

The document contains solutions to three Python programming questions. The first question involves reversing a string and counting its vowels, the second checks if a number is even or odd, and the third simulates creating a virtual environment to sort a list of integers using NumPy. Each solution includes code snippets and explanations of the steps involved.

Uploaded by

munthasab15
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)
46 views2 pages

Python Programming Assignment 01

The document contains solutions to three Python programming questions. The first question involves reversing a string and counting its vowels, the second checks if a number is even or odd, and the third simulates creating a virtual environment to sort a list of integers using NumPy. Each solution includes code snippets and explanations of the steps involved.

Uploaded by

munthasab15
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

# Question 1: Write a Python program that takes a string as input and prints:

# 1. The string in reverse order.


# 2. The number of vowels in the string.

# solution
string = input("Enter a String: ")
print("The string is: ", string)

# 1. The string in reverse order.


print("The string in reverse order is: ", string[::-1])
# 2. The number of vowels in the string.
vowels = "aeiouAEIOU"
count = 0
for char in string:
if char in vowels:
count += 1

print("The number of vowels in the string is: ", count)

print("---------------------------------------------------------\n Question 2")

"""
Question 2: Hands-on Coding Project

Problem Statement: Create a Python program that:


● Takes an input number from the user.
● Checks whether the number is even or odd.
● Prints the result.
"""

# Solution
number = int(input("Enter a number: "))
if number % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")

print("---------------------------------------------------------\n Question 3")

"""

Question 3: Virtual Environment Application

Problem Statement: Create a Python program that:


1. Takes a list of integers as input.
2. Creates a new virtual environment called sortenv.
3. Installs a package (such as numpy) in the virtual environment.
4. Sorts the list using [Link]().
5. Prints the sorted list.
"""

# Solution
import numpy as np
# Function to sort the list
def sort_list(arr):
return [Link](arr)
# Simulating virtual environment setup
def setup_virtual_env():
print('Step 1: Create a virtual environment using:')
print(" Python -m venv sortenv")
print('Step 2: Activate the virtual envorinment')
print(' Windows: sortenv\\Scripts\\activate')
print(' macOS/Linux: source sortenv/bin/activate')
print('Step 3: install NumPy in the virtual environment')
print(' pip install numpy')
print('Step 4: Now, sorting the list using NumPy...')
# Taking user input as a list of integers
try:
user_input = input('Enter a list of numbers separated by spaces: ')
num_list = list(map(int,user_input.split()))
# Running virtual environment simulation
setup_virtual_env()
# Sorting and displaying the sorted list
print('Sorted list: ',sort_list(num_list))
except ValueError:
print('Invalid input! Please enter a list of integers.')

You might also like