0% found this document useful (0 votes)
3 views

Python-Programming-Assignment-01

The document outlines a Python programming assignment with three questions. The first question involves creating functions to reverse a string and count vowels, the second checks if a number is odd or even, and the third demonstrates sorting numbers using a virtual environment with NumPy. Each question includes code snippets and user input handling.

Uploaded by

fazalabbas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python-Programming-Assignment-01

The document outlines a Python programming assignment with three questions. The first question involves creating functions to reverse a string and count vowels, the second checks if a number is odd or even, and the third demonstrates sorting numbers using a virtual environment with NumPy. Each question includes code snippets and user input handling.

Uploaded by

fazalabbas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Programming Assignment 01

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

def reverse_text(input_str):
return input_str[::-1]

def count_vowel(input_str):
vowel_count = 0
for char in input_str.lower():
if char in {'a','e','i','o','u'}:
vowel_count += 1
return vowel_count

user_text = input("Type something: ")


print("Backwards:", reverse_text(user_text))
print("Vowel count:", count_vowel(user_text))

Question 2:

def odd_even_check(num):
return "Even" if num % 2 == 0 else "Odd"

for attempt in range(2):


try:
user_num = int(input("Enter whole number: "))
print(f"{user_num} is {odd_even_check(user_num)}")
except:
print("Numbers only please")

Question 3: Virtual Environment Application

import numpy as np

def sort_numbers(number_list):
print("Creating virtual environment...")
print("(In real use: python -m venv sortenv)")
print("(Then: pip install numpy)")
return np.sort(number_list)

try:
numbers = [int(x) for x in input("Enter numbers with spaces:").split()]
print("Sorted:", sort_numbers(numbers))
except:
print("Only numbers allowed")

You might also like