{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Q1 : Write a while loop to add all the numbers from 0 to 100." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q2 : Write a program using a while loop that prompts the user for a hobby 3 times, then appends each one to a list and finally return the list.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q4 : Write a program using while loop to iterate through the list and if there is a 100, print it with its index number. i.e.: \"There is a 100 at index no: 5\". \n", "\n", "**Hint:**  Do not forget provide some response if 100 is not found." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q3 : Write a program that prompts the user to enter numbers, one per line, until he/she types 'No' ( Ask to type Y/N to continue or quit after every integer input ) and keep a running sum of the numbers. Only print out the sum after all the numbers are entered.\n", "\n", "**Hint:**  Do not create a list! Each time you read in a number, you can immediately use it for your sum, and then be done with the number just entered." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q5 : Using while loop and an if statement write a program which appends all the elements in a list to a new list unless the element is an empty string: \"\".\n", "\n", "**Input**: `my_list = [\"Joe\", \"Sarah\", \"Mike\", \"Jess\", \"\", \"Matt\", \"\", \"Greg\"]`\n", "\n", "**Output:** `[\"Joe\", \"Sarah\", \"Mike\", \"Jess\", \"Matt\", \"Greg\"]`\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q6 : For the list in Q5, write a program that stops appending items to the new list as soon as it encounters an empty string." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q7 : Write a program, which asks for the initial balance K0 and for the interest rate. The program shall calculate the new capital K1 after one year including the interest. Extend the program with a while-loop, so that the capital Kn after a period of n years can be calculated." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q8 : Using while loop and conditional statement, write a program that takes a string as user input and returns a dictionary containing the all characters(except whitespace) of the string that occured more than once as keys and their count as values, sorted in decreasing order of their counts. If no character is repeated in the string, display `No character is repeated.`\n", "\n", "**Hint:** Which data type contains unique element from an iterable? We can use the count() method to keep counts of the characters. Also, donot forget to convert all characters to lowercase at first.\n", "\n", "**Sample input1**: `Python`\n", "\n", "**Sample output1:** `No character is repeated.`\n", "\n", "**Sample input1**: `Geeks for geeks`\n", "\n", "**Sample output1:** `{'e': 4, 'g': 2, 's': 2, 'k': 2}`" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### \n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }