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")