Skip to content

Week 3 Python Graded Assignment GRPA 2

week 3 Python Graded Assignments GRPA 2 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 2 – For Loop – GRADED

Bit of Wisdom 📖 In context of general incremental definite loops the structure of while loop can be converted to a for loop using range. Refer this.

# the wile loop
i = 0 # initialization
while i<10: # condition
    print(i) # body
    i+=2 # update

# same with for loop
for i in range(0,10,2): # range combines initalization, temination and update.

Write a multi functional program that takes input task from standard input and does the corresponding taks accordingly. Note that the useage of for loop is not allowed in this exercise.

  1. Part 1 – while loop to for loop
    1. factorial – print factorial of a given non-negative integer n (Type: Accumulation)
      Input – n:int
    2. even_numbers – Print the even numbers from 0 (including) till the given input number n(including) in multiple lines (Type: Just Iterating)
      Input – n:int
    3. power_sequence – Print the sequence 1, 2, 4, 8, 16, … n terms in same line in multiple lines, where n is taken from the input(Type: Mapping)
      Input – n:int
  2. Part 2 – for loop With range
    • sum_not_divisible – Print the sum of positive less that the given number n and not divisible by 4 and 5. (Type: Filtered Accumulation)
      Input – n:int
    • from_k – Starting from 100 and going in the decreasing order, print the reverse(digits reversed) of first n numbers starting from k which do not have the digit 5 and 9 and is odd number in multiple lines.
      Input – n:intk:int
  3. part 3 – for loop with iterables.
    • string_iter – Given a string s of digits print the numerical value of the digit multiplied by the previous digit. Assume the pevious digit for the first element to be 1.
      Input – s:str
    • list_iter – Print the elements of a list l line by line in the format {element} - type: {type} where the element is the current element being iterated by the for loop and type is the type of the element. (Even though list are not covered in this week, this is included to demonstrate the similarity between iterating characters in a str and items in a list)
      Input – l:list