|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "ename": "ModuleNotFoundError", |
| 10 | + "evalue": "No module named 'urduhack'", |
| 11 | + "output_type": "error", |
| 12 | + "traceback": [ |
| 13 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 14 | + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", |
| 15 | + "Cell \u001b[1;32mIn[1], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# Take input from the user\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01murduhack\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01muk\u001b[39;00m\n\u001b[0;32m 3\u001b[0m input_string \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEnter a sentence: \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 5\u001b[0m \u001b[38;5;66;03m# Split the input sentence into words\u001b[39;00m\n", |
| 16 | + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'urduhack'" |
| 17 | + ] |
| 18 | + } |
| 19 | + ], |
| 20 | + "source": [ |
| 21 | + "# Take input from the user\n", |
| 22 | + "\n", |
| 23 | + "input_string = input(\"Enter a sentence: \")\n", |
| 24 | + "\n", |
| 25 | + "# Split the input sentence into words\n", |
| 26 | + "words = input_string.split()\n", |
| 27 | + "\n", |
| 28 | + "# Calculate the number of words in the sentence\n", |
| 29 | + "words_num = len(words)\n", |
| 30 | + "\n", |
| 31 | + "# Calculate the length of the entire string\n", |
| 32 | + "string_length = len(input_string)\n", |
| 33 | + "\n", |
| 34 | + "# Initialize variables for shortest string and its length\n", |
| 35 | + "shortest_string = None\n", |
| 36 | + "shortest_length = float('inf')\n", |
| 37 | + "\n", |
| 38 | + "# Iterate through each word in the sentence\n", |
| 39 | + "for word in words:\n", |
| 40 | + " # Update the shortest string if the current word is shorter\n", |
| 41 | + " if len(word) < shortest_length:\n", |
| 42 | + " shortest_string = word\n", |
| 43 | + " shortest_length = len(word)\n", |
| 44 | + "\n", |
| 45 | + "# Find all shortest words of the same length\n", |
| 46 | + "shortest_words = [word for word in words if len(word) == shortest_length]\n", |
| 47 | + "\n", |
| 48 | + "# Print the results\n", |
| 49 | + "print(\"Number of words in the sentence:\", words_num)\n", |
| 50 | + "print(\"Length of the entire string:\", string_length)\n", |
| 51 | + "print(\"Length of the shortest string:\", shortest_length)\n", |
| 52 | + "print(\"All shortest words of length\",shortest_words, \":\", shortest_length)" |
| 53 | + ] |
| 54 | + } |
| 55 | + ], |
| 56 | + "metadata": { |
| 57 | + "kernelspec": { |
| 58 | + "display_name": "Python 3", |
| 59 | + "language": "python", |
| 60 | + "name": "python3" |
| 61 | + }, |
| 62 | + "language_info": { |
| 63 | + "codemirror_mode": { |
| 64 | + "name": "ipython", |
| 65 | + "version": 3 |
| 66 | + }, |
| 67 | + "file_extension": ".py", |
| 68 | + "mimetype": "text/x-python", |
| 69 | + "name": "python", |
| 70 | + "nbconvert_exporter": "python", |
| 71 | + "pygments_lexer": "ipython3", |
| 72 | + "version": "3.12.0" |
| 73 | + } |
| 74 | + }, |
| 75 | + "nbformat": 4, |
| 76 | + "nbformat_minor": 2 |
| 77 | +} |
0 commit comments