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.
print(i)
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.
- Part 1 – while loop to for loop
factorial
– print factorial of a given non-negative integern
(Type: Accumulation)
Input –n:int
even_numbers
– Print the even numbers from 0 (including) till the given input numbern
(including) in multiple lines (Type: Just Iterating)
Input –n:int
power_sequence
– Print the sequence 1, 2, 4, 8, 16, …n
terms in same line in multiple lines, wheren
is taken from the input(Type: Mapping)
Input –n:int
- Part 2 – for loop With range
sum_not_divisible
– Print the sum of positive less that the given numbern
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 firstn
numbers starting fromk
which do not have the digit 5 and 9 and is odd number in multiple lines.
Input –n:int
,k:int
- part 3 – for loop with iterables.
string_iter
– Given a strings
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 listl
line by line in the format{element} - type: {type}
where theelement
is the current element being iterated by thefor
loop andtype
is the type of theelement
. (Even though list are not covered in this week, this is included to demonstrate the similarity between iterating characters in astr
and items in alist
)
Input –l:list