Skip to content

Week 3 Python Graded Assignment GRPA 1

week 3 Python Graded Assignments GRPA 1 IIT Madras Complete  Solutions Are Discussed In the Drive Link Given Below See Bottom And Request  We Hope This Might Help You All In Matching Answers . Or For Some Others Reasons Not Able To Complete Graded Assignments 

GrPA 1 – While Loop – GRADED

✅ Important Note on while loop🔁:

  • Use while only when the number of iterations is indefinite.
  • If you can term the steps as do n times, do once for each item, etc. use for loop instead.
  • If you can only term the steps as do until something happens. Like when user inputs 10.

A bit of wisdom 📖 There are maily two ways in which while loops are used in the context of taking inputs until a terminal word.

# method 1
a = input()
while a != terminal_word: # opposite of the terminal condition
    # do something with a
    a = input() # take the next a

# method 2
while True: # loop forever
    a = input()
    if a == terminal_word: # the terminal condition
        break
    # do something with a

Problem Statement

Problem type – Standard Input – Standard Output

NOTE: None of this problem statements can be written using a for since the number of repetition is indefinite.

Implement different parts of a multi-functional program based on an initial input value. Each part of the program will handle various tasks related to accumulation, filtering, mapping, and combinations of these operations. None of the tasks should use explicit loops for definite repetitions, and the program should handle indefinite inputs gracefully.

Tasks

  1. Accumulation – Accumulating a final result
    1. sum_until_0: Continuously read integers from standard input until you receive a zero. Print the sum of these integers.
    2. total_price: Continuously read pairs of integers from standard input, representing the quantity and price of items, until you receive the string “END”. Print the total price of all items.
  2. Filtering – Selecting based on a criterion
    1. only_ed_or_ing: Continuously read strings from standard input until you encounter the word “STOP” (case insensitive and not included in the output). Print only those strings that end with “ed” or “ing” (case insensitive).
    2. reverse_sum_palindrome: Continuously read positive integers from standard input until you encounter a “-1″(not included in the output). Print only those integers for which the sum of the number and its reverse is a palindrome.
  3. Mapping – Applying the same operation to different items
    1. double_string: Continuously read lines from standard input until an empty line is encountered. Print each line repeated twice.
    2. odd_char: Continuously read strings from standard input until you encounter a string ending with a “.”(include that string with the “.” in the output). Extract characters at odd positions (starting from 1) of each line, and print the results in a single line separated by spaces.
  4. Filter and Map – Applying an operation to selected items
    1. only_even_squares: Continuously read numbers from standard input until “NAN” is encountered. Print the square of each number only if it is even.
  5. Filter and Accumulate – Accumulating a result with selected items
    1. only_odd_lines: Continuously read lines from standard input until “END”(not included in the output) is encountered. Create a string by prepending only the odd lines (starting from 1) with a newline character in between, and print the result which will be the odd lines in reverse order.