The Joy of Computing using Python | Week 11

Session: JAN-APR 2024

Course Name: The Joy of Computing using Python

Course Link: Click Here

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 11 Answers


Q1. Select the correct statement regarding selenium library
Selenium is primarily used for web browser automation
The web driver in selenium allows a way to interact with web browsers
The Keys Class provides a set of special keys that can be used for keyboard interaction
All of the above

Answer: All of the above


Q2. Which of the following tasks in WhatsApp can be automated using selenium?
Sending Media Files
Reading Messages
Creating and Managing Groups
Updating Profile Information

Answer: a), b), c), d)


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 11 Answers


Q3. Read the given code and identify the correct statement.
does_something returns a list of all time zones in Asia
the above code prints all time zones in Asia
The output of the code can change depending on the version of pytz used
All of the above

Answer: All of the above


Q4. Read the given code. What is the output of does_something(2022,2,29).(NAT)

Answer: 0


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 11 Answers


Q5. Read the given code.
Assume the file years.txt contains the following data.
What is the output of the code (NAT)

Answer: 2


Q6. Read the given code.
Enter the value of int(count_something(1996)==count_something(2024))

Answer: 1


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 11 Answers


Q7. Read the given code.
Enter the value returned by count_(1990,2024)

Answer: 9


Q8. In addition to the first birthday celebration, Koreans often celebrate “MiSeDol,” which marks the completion of the 100th day after a baby’s birth. This is considered another significant milestone. Given an input birthdate, the following code tries to calculate the date of “MiSeDol”, but the code might contain errors. Identify the line number corresponding to the error. In the absence of an error answer -1.

Answer: -1


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 11 Answers


Q9. Read the given code.
Find the value returned by finds_something (2000,12)

Answer: 5


Q10. Read the following code. What does count_something(2024,1) return ?

Answer: 23


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 11 Answers


The Joy of Computing using Python Programming Assignment

Question 1

Write the following functions:
(1) factors: accept a positive integer n as argument. Return the set of all factors of n.
(2) common_factors: accept two positive integers a and b as arguments. Return the set of common factors of the two numbers. This function must make use of factors.
(3) factors_upto: accept a positive integer n as argument. Return a dict D, whose keys are integers and values are sets. Each integer in the range [1,n], endpoints inclusive, is a key of D. The value corresponding to a key, is the set of all factors of key. This function must make use of factors.

The idea we are trying to bring out here is to make use of pre-defined functions whenever needed.

Solution:

def factors(n):
    factor_set = set()
    for ips in range(1, n + 1):
        if n % ips == 0:
            factor_set.add(ips)
    return factor_set


def common_factors(a, b):
    factors_a = factors(a)
    factors_b = factors(b)
    return factors_a.intersection(factors_b)

def factors_upto(n):
    factors_dict = {}
    for i in range(1, n + 1):
        factors_dict[i] = factors(i)
    return (factors_dict)

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 11 Answers


Question 2

A clockwise rotation of a list consists of taking the last element and moving it to the beginning of the list. For instance, if we rotate the list [1, 2, 3, 4, 5], we get [5, 1, 2, 3, 4]. If we rotate it again, we get [4, 5, 1, 2, 3]. Your task is to perform k rotations of a list.
The first line of input contains a non-empty sequence of comma-separated integers. The second line of input is a positive integer k. Perform k rotations of the list and print it as a sequence of comma-separated integers.

Solution:

def rotate_clockwise(lst, k):
    npk = len(lst)
    k %= npk
    rotated_list = lst[-k:] + lst[:-k]
    return rotated_list

input_list = input().split(",")  
k = int(input()) 
rotated_result = rotate_clockwise(input_list, k)
print(",".join(rotated_result))

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 11 Answers


Question 3

Consider a spiral of semicircles. We start at a point P0​ on the x-axis with coordinates (l,0). The first arm of the spiral ends at P1​ with coordinates (r,0). The second arm of the spiral starts at P1​ and ends at the center of the first arm, P2​. The third arm starts from P2​ and ends at P3​ which happens to be the center of the second arm. And finally, the fourth arm starts at P3​ and ends at P4​, the center of the third arm.

Write two functions named spiral_iterative and spiral_recursive, each of which accepts three arguments:
left: x-coordinate of the point P0​
right: x-coordinate of the point P1​
n: the number of arms in the spiral
Both functions should return the the x-coordinate of Pn​, the point at which the nth arm of the spiral ends.

Solution:

def spiral_iterative(left, right, n):
 
    for ipl in range(1,n):
      center = (left + right)/2
      if ipl % 2 :
        left = center
      else:
        right = center
    return center
    
def spiral_recursive(left, right, n):
    if n == 1:
        return right
    else:
        center = (left + right) / 2
        return spiral_recursive(right, center, n - 1)

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 11 Answers


More Weeks of The Joy of Computing Using Python: Click here

More Nptel Courses: Click here


Session: JULY-DEC 2023

Course Name: The Joy of Computing using Python

Course Link: Click Here

These are answers of The Joy of Computing using Python Assignment 11 Answers


Q1. Which library is used for browser automation?
nltk
numpy
selenium
PIL

Answer: selenium


Q2. What the given statement will return?
time.time()

Time in seconds.
Current date and time.
Time in minutes
The current date, time and year

Answer: Time in seconds.


Q3. Identify the library that can be used to get all timezones:
selenium
calender
nltk
pytz

Answer: pytz


These are answers of The Joy of Computing using Python Assignment 11 Answers


Q4. The output of the following code will be?
Date and time in dd- mm-yy hh:MM:ss:ms respectively.
Time and date in hh:MM:ss:ms dd- mm-yy respectively.
Date and time in mm-dd-yy hh:MM:ss:ms respectively.
Date and time in yy- mm-dd hh:MM:ss:ms respectively.

Answer: Date and time in yy- mm-dd hh:MM:ss:ms respectively.


Q5. We can use the selenium web driver for different browsers.
True
False

Answer: True


Q6. What will be the output of the following code?
Print the current date and time of all time zones.
Print the current date and time of specific time zones.
Print the current date of all time zones.
Print the current date of some specific time zones.

Answer: Print the current date and time of all time zones.


These are answers of The Joy of Computing using Python Assignment 11 Answers


Q7. What will be the output if the system date is 10 December 2021(Friday)?
5
3
4
error

Answer: 4


Q8. Which statement will return the calendar for a whole year?
calendar.month(year)
calendar(year)
calendar.prcal(year)
calendar.year(year)

Answer: calendar.prcal(year)


These are answers of The Joy of Computing using Python Assignment 11 Answers


Q9. By which statement can we come out of the loop?
continue
leave
catch
break

Answer: break


These are answers of The Joy of Computing using Python Assignment 11 Answers


Q10. How to check for the leap year?
calendar.leap(year)
calendar.is_leap(year)
calendar.isleap(year)
calendar.checkleap(year)

Answer: calendar.isleap(year)


These are answers of The Joy of Computing using Python Assignment 11 Answers


The Joy of Computing using Python Programming Assignmnet

Question 1
Take 3 sides of a triangle as an input and find whether that triangle is a right angled triangle or not. Print ‘YES’ if a triangle is right angled triangle or ‘NO’ if it’s not.
Input:
3
4
5
Output
YES

Solution:

a1=int(input())
b3=int(input())
c=int(input())
L=[a1,b3,c]
h=max(L)
L.remove(h)
if h**2==L[0]**2+L[1]**2:
  print("YES",end="")
else:
  print("NO",end="")

These are answers of The Joy of Computing using Python Assignment 11 Answers


Question 2
Write a program that accepts a hash-separated sequence of words as input and prints the words in a hash-separated sequence after sorting them alphabetically in reverse order.
Input:
hey#input#bye
Output:
input#hey#bye

Solution:

LGF=sorted(input().split("#"),reverse=True)
print("#".join(LGF),end="")

These are answers of The Joy of Computing using Python Assignment 11 Answers


Question 3
Write a program which takes two integer a and b and prints all composite numbers between a and b.(both numbers are inclusive)
Input:
10
20
Output:
10
12
14
15
16
18
20

Solution:

prime_nb=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 
       59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
       127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 
       191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
       257, 263, 269, 271, 277, 281, 283, 293]
a=int(input())
b=int(input())
for i in range(a,b+1):
    if i not in prime_nb:
      print(i)

These are answers of The Joy of Computing using Python Assignment 11 Answers

More Weeks of The Joy of Computing Using Python: Click here

More Nptel Courses: Click here


Session Jan-Apr 2023

Course Name: The Joy of Computing using Python

Course Link: Click Here

These are answers of The Joy of Computing using Python Assignment 11 Answers


Q1. Which statement will return the calendar for a whole year?
a. calendar.month(year)
b. calendar(year)
c. calendar.prcal(year)
d. calendar.year(year)

Answer: c. calendar.prcal(year)


Q2. By which statement can we come out of the loop?
a. continue
b. leave
c. catch
d. break

Answer: d. break


These are answers of The Joy of Computing using Python Assignment 11 Answers


Q3. What time.time() will return?
a. Time in seconds.
b. Current date and time.
c. Time in minutes
d. The current date, time and year.

Answer: a. Time in seconds.


Q4. Which library used to get all timezones?
a. selenium
b. calender
c. nltk
d. pytz

Answer: d. pytz


These are answers of The Joy of Computing using Python Assignment 11 Answers


Q5. What is the output of the following code:

image 28

a. Print the current date and time of all time zones.
b. Print the current date and time of specific time zones.
c. Print the current date of all time zones.
d. Print the current date of some specific time zones.

Answer: a. Print the current date and time of all time zones.


Q6. In the page rank algorithm,
a. We randomly travel from node to node without any relationship.
b. We randomly travel from node to neighbor node.
c. The maximum visited node will be the leader.
d. 2 and 3
e. 1 and 3

Answer: d. 2 and 3


These are answers of The Joy of Computing using Python Assignment 11 Answers


Q7. If we perform the page rank algorithm on the web as a graph, which of the following is true?
a. Websites are nodes, and hyperlinks in websites are edges.
b. Hyperlinks in websites are nodes, and websites are edges.
c. Websites will work as nodes and edges.
d. Hyperlinks will work as nodes and edges.

Answer: a. Websites are nodes, and hyperlinks in websites are edges.


Q8. In the page rank algorithm, the leader is decided by?
a. A node(person) with a maximum number of outgoing edges.
b. A node(person) with a maximum number of incoming edges.
c. A node(person) that is visited maximum times.
d. Can not decide.

Answer: c. A node(person) that is visited maximum times.


These are answers of The Joy of Computing using Python Assignment 11 Answers


Q9. Which statement is correct about the following program?

image 29

a. The graph will go up when guess and pick are the same.
b. The graph will go down when guess and pick are the same.
c. The graph will go up when guess and pick are not the same.
d. Both B and C

Answer: d. Both B and C


Q10. Which of the following is not used as conditional statement in Python?
a. switch
b. if…else
c. elif
d. None of the mentioned above

Answer: a. switch


These are answers of The Joy of Computing using Python Assignment 11 Answers


The Joy of Computing using Python Programming Assignmnet

Question 1

Take 3 sides of a triangle as an input and find whether that triangle is a right angled triangle or not. Print ‘YES’ if a triangle is right angled triangle or ‘NO’ if it’s not.
Input:
3
4
5
Output
YES

Solution:

a=int(input())
b=int(input())
c=int(input())
L=[a,b,c]
h=max(L)
L.remove(h)
if h**2==L[0]**2+L[1]**2:
  print("YES",end="")
else:
  print("NO",end="")

These are answers of The Joy of Computing using Python Assignment 11 Answers


Question 2

Write a program that accepts a hash-separated sequence of words as input and prints the words in a hash-separated sequence after sorting them alphabetically in reverse order.
Input:
hey#input#bye
Output:
input#hey#bye

Solution:

L=sorted(input().split("#"), reverse=True)
print("#".join(L),end="")

These are answers of The Joy of Computing using Python Assignment 11 Answers


Question 3

Write a program which takes two integer a and b and prints all composite numbers between a and b.(both numbers are inclusive)
Input:
10
20
Output:
10
12
14
15
16
18
20

Solution:

prime=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
       59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
       127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
       191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
       257, 263, 269, 271, 277, 281, 283, 293]
a=int(input())
b=int(input())
for i in range(a,b+1):
    if i not in prime:
      print(i)

These are answers of The Joy of Computing using Python Assignment 11 Answers

More Weeks of The Joy of Computing using Python: Click Here

More Nptel courses: https://progiez.com/nptel-assignment-answers/


These are answers of The Joy of Computing using Python Assignment 11 Answers
The content uploaded on this website is for reference purposes only. Please do it yourself first.