Sample Paper 2 by Teachoo

Computer Science - Class 11
Teachoo Sample Paper

## g) Use a loop to repeat the menu until the user chooses to exit.

``` print( "Menu" ) ```

``` print( "1. Reverse a String" ) ```

``` print( "2. Count Vowels" ) ```

``` print( "3. Remove Duplicates" ) ```

``` print( "4. Exit" ) ```

``` ```

``` choice = int(input( "Enter your choice: " )) ```

``` while choice not in [ 1 , 2 , 3 , 4 ]: ```

```     print( "Invalid choice. Please try again." ) ```

```     choice = int(input( "Enter your choice: " )) ```

``` while choice != 4 : ```

```     if choice == 1 : ```

```         s = input( "Enter a string: " ) ```

```         reversed_s = s[:: -1 ] ```

```         print( "The reversed string is:" , reversed_s) ```

```     elif choice == 2 : ```

```         s = input( "Enter a string: " ) ```

```         vowels = "aeiouAEIOU" ```

```         count = 0 ```

```         for c in s: ```

```             if c in vowels: ```

```                 count += 1 ```

```         print( "The number of vowels is:" , count) ```

```     elif choice == 3 : ```

```         s = input( "Enter a string: " ) ```

```         no_duplicates = "" .join(set(s)) ```

```         print( "The string without duplicates is:" , no_duplicates) ```

```     print( "\nMenu" ) ```

```     print( "1. Reverse a String" ) ```

```     print( "2. Count Vowels" ) ```

```     print( "3. Remove Duplicates" ) ```

```     print( "4. Exit" ) ```

```     choice = int(input( "Enter your next choice: " )) ```

```     while choice not in [ 1 , 2 , 3 , 4 ]: ```

```         print( "Invalid choice. Please try again." ) ```

```         choice = int(input( "Enter your next choice: " )) ```

``` print( "Thank you for using the program. Goodbye!" ) ```