The Joy Of Computing Using Python Week 3 : Assignment 1 | NPTEL | [Jan 2024]

The Joy of Computing using Python Week 3 - Assignment 1 | NPTEL | Answer with Explanation

The Joy of Computing using Python Week 2 Assignment 1  NPTEL   [Jan 2023]
"Discover the Excitement of Computing with Python | Week 3 Multiple Choice Questions - Get ready to enhance your programming skills and deepen your understanding of the Python language with this week 3 MCQ on 'The Joy of Computing using Python'. Test your knowledge and boost your confidence as a Python programmer today!"

Consider the following code snippet:

elements = []

n = int(input("Enter the number of elements: "))

for i in range(n):
    item = input ("Enter element " + str(i +1) +": ")
    elements. append (item)

print ("The entered elements are:", elements)
What does the code do?
a. Takes a list of numbers as input, appends each number to a list, and prints the list of numbers
b Takes a list of elements as input, appends each element to a list, and prints the list of elements
c. Takes the count of elements followed by the same number of elements as input, appends each element to a list, and prints the list of elements
d. Takes the count of elements, appends each element to a list, and prints the count of elements entered.
Answer
c. Takes the count of elements followed by the same number of elements as input, appends each element to a list, and prints the list of elements



Output Enter the number of elements: 3 Enter element 1: 1 Enter element 2: 2 Enter element 3: 3 The entered elements are: ['1', '2', '3']

Data Structure is a way by which you can organize/arrange your data. Which of the following statements are true about List Data Structure: [MSQ]

a. It is a flexible Data Structure
b. Elements could be added to a list.
c. Elements could be subtracted from a list.
d. This_is_not_List = [ ] is an empty list
Answer

a. It is a flexible Data Structure
b. Elements could be added to a list.
c. Elements could be subtracted from a list.
d. This_is_not_List = [ ] is an empty list

It is a flexible Data Structure:

Lists allow you to store various data types (integers, strings, floats, etc.) within the same list.
They can grow or shrink dynamically as needed, unlike arrays with fixed sizes.
They support a range of operations like adding, removing, accessing, and modifying elements.

Elements could be added to a list:
You can use methods like append(), insert(), or extend() to add elements to a list at the end, specific positions, or from other sequences.

This_is_not_List = [] is an empty list:
The syntax [] correctly creates an empty list named This_is_not_List.

Elements could be subtracted from a list:
Lists don't have a direct "subtraction" operation. However, you can achieve similar behavior:
Remove specific elements using remove() or pop().
Filter out unwanted elements using list comprehensions or loop-based approaches.

Consider the following code snippet:

L = ['Amar', 'Akbar', 'Anthony']
print(L[2], ‘is brother of', L[1], ‘and’, L[0])

What does the above code print?

a. Amar, Akbar, Anthony
b. amar is brother of anthony and akbar
c. Amar is brother of Anthony and Akbar
d. Anthony is brother of Akbar and Amar
Answer

d. Anthony is brother of Akbar and Amar
Python lists are indexed starting from 0, so the first element is at index 0, the second at index 1, and so on.
The print() function is used to display output to the console.
String concatenation allows combining strings and variables using commas within the print() function.

Consider the following code snippet:

numbers = [2, 4, 6, 8, 10]

for i in range (len (numbers) ) :
    numbers [i] *= 2
print ("Updated list:", numbers)

What does the code do?

a. Takes a list of numbers, multiplies each number by 2, and prints the updated list
b. Takes a list of numbers, appends each number to the list twice, and prints the updated list
c. Takes a list of numbers, removes even numbers from the list, and prints the updated list
d. Takes a list of numbers, divides each number by 2, and prints the updated list
Answer

a. Takes a list of numbers, multiplies each number by 2, and prints the updated list

Output: Updated list: [4, 8, 12, 16, 20]

What will be the output of the following Python code?

import random
def genetic_evolution(binary_string) :
    mutation_probability = 0.1 # adjust this probability as needed
    evolved_string = ""
    for bit in binary_string:
        if random.random() < mutation_probability:
            evolved_string += "1" if bit == "0” else "0"
        else:
            evolved_string += bit
    return evolved_string
initial_string = "0000000000"
result = genetic_evolution(initial_string)
print (result)
a. "1111111111"
b. "0000000000"
c. A string with some 1s and some 0s
d. The function will raise an error
Answer

b. "0000000000"

Consider the following code snippet:

numbers = []

n = int(input("Enter the number of elements: "))
for i in range(n):
    num = int(input ("Enter number "+ str(i + 1) +": "))
    numbers.append(num)
result = sum(numbers)
average = result /n
print ("Sum of the numbers:", result)

print ("Average of the numbers:", average)

a. Takes a list of numbers as input, computes the sum of the numbers, and prints the sum along with the average
b. Takes the count of elements, computes the sum of the elements, and prints the sum along with the average
c. Takes a list of numbers as input, computes the average of the numbers, and prints the average along with the sum
d. None of the above
Answer
b. Takes the count of elements, computes the sum of the elements, and prints the sum along with the average

Enter the number of elements: 2
Enter number 1: 5
Enter number 2: 5
Sum of the numbers: 10
Average of the numbers: 5.0

What will be the output of the following Python code?

import random

def permutation_example (word) :
    word_list = list (word)
    random.shuffle (word_list)
    shuffled_word = ''.join(word_list)
    return shuffled_word

input_word = "python"

result = permutation_example(input_word)

print (result)

a. "Python"
b. A random permutation of the letters in "python"
c. "random"
d. The function will raise an error
Answer

b. A random permutation of the letters in "python"

O/P: ophynt

Consider the following code snippet:

numbers = [1, 2, 3, 4,5]
new_numbers = []
for num in numbers:

    new_numbers.insert(0, num) #insert()isa function that inserts a value at a given index

print ("Updated list:", new_numbers)

a. Reverses the numbers list and stores it in new_numbers.
b. Creates an empty list named new_numbers and appends elements from numbers to it in reverse order.
c. Produces an error due to an invalid function used for list manipulation.
d. Generates a new list new_numbers with elements from numbers in the same order as numbers.
Answer


a. Reverses the numbers list and stores it in new_numbers.
b. Creates an empty list named new_numbers and appends elements from numbers to it in reverse order.

Output:
Updated list: [5, 4, 3, 2, 1]

Which of the following are the examples of Social Computing/Crowd Computing: [MSQ]

a. Wikipedia
b. Stack Exchange
c. Quora
d. Facebook
Answer
All of the options you listed, a, b, c, and d, are examples of Social Computing/Crowd Computing. Here's a breakdown of why:

Social Computing:

Refers to the use of online communities and technologies to support collaboration and knowledge sharing among people.
These platforms leverage the collective intelligence and contributions of users to generate content, solve problems, and make decisions.
Crowd Computing:

A subcategory of Social Computing specifically focused on using distributed human effort to solve tasks that are difficult or impossible for computers alone.
Participants contribute their time, skills, and knowledge to achieve a common goal.

Consider the following code snippet:

for i in range(1, 21):
    if i%3 == 0 and i% 5== 0:
        print ("FizzBuzz")
    elif i % 3 == 0:
        print ("Fizz")
    elif i% 5 ==0 :

        print ("Buzz")
    else:
        print (i)

Answer
Prints numbers from 1 to 20, replacing multiples of 3 and 5 with "FizzBuzz", multiples of 3 with "Fizz", and multiples of 5 with "Buzz".

Output:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz

PYQ | The Joy of Computing using Python - Course | NPTEL

Learn Python for free with Computer Course - CompEduBox Android app. Share with your Friends

Disclaimer:
"This page contains multiple choice questions (MCQs) related to The Joy of Computing using Python . The answers to these questions are provided for educational and informational purposes only.These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself."

The Joy of Computing using Python Week 2,NPTEL ,,Assignment 1 [Jan 2024],noc24_cs57
Joy of Computing using Python

Post a Comment

0 Comments