{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "authorship_tag": "ABX9TyOqQvMYSVHffQwcSDCIXmsN", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "source": [ "# Counting Vowels in a Sentence\n", "\n", "\n", "## Problem\n", "\n", "You are tasked with creating a Python script that counts the number of vowels in a given sentence. Your program should prompt the user to enter a sentence, and then output the total count of vowels present in that sentence. The program should treat both uppercase and lowercase vowels as equivalent.\n", "\n", "Your task is to write a Python script that accomplishes this, utilizing functions and loops as necessary." ], "metadata": { "id": "oQbsz2YwDc_f" } }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "XAU5DlE0DZpU", "outputId": "43f94197-a8b0-42c5-fb3b-248340f81b1d" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Enter a sentence: Hello I am a Sales Expert\n", "Number of vowels: 9\n" ] } ], "source": [ "def count_vowels(sentence):\n", " vowels = 'aeiouAEIOU'\n", " vowel_count = 0\n", " for char in sentence:\n", " if char in vowels:\n", " vowel_count += 1\n", " return vowel_count\n", "\n", "sentence = input(\"Enter a sentence: \")\n", "print(\"Number of vowels:\", count_vowels(sentence))\n" ] }, { "cell_type": "markdown", "source": [ "This script defines a function count_vowels that takes a sentence as input and returns the count of vowels in it. It iterates over each character in the sentence and checks if it is a vowel. If it is, it increments the count. Finally, it prints out the total count of vowels in the sentence.\n", "\n", "\n" ], "metadata": { "id": "euH9m_htD6tG" } } ] }