0% found this document useful (0 votes)
12 views

Week 3

SOFT SKILLS NPTEEL

Uploaded by

riyaranirr2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Week 3

SOFT SKILLS NPTEEL

Uploaded by

riyaranirr2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Joy of Programming using Python

TA: Rupesh Kumar


Friday August 9, 2024

1. Consider the following code snippet:

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: Option c

2. 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: All the options are correct.
List is a flexible data structure. Python lists allow us to add or delete elements form a
list. It is mutable. We can use list.append(element) to add elements to a list. We can
use list.pop(index) to remove element from the list.

3. Consider the following code snippet:


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: Option d
L[2] = “Anthony”
L[1] = “Akbar”
L[0] = “Amar”

4. Consider the following code snippet:

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: Option a
i=0
numbers[0] = 2
numbers[0] = 2 * 2 = 4
i=1
numbers[1] = 4 * 2 = 8
5. What will be the output of the following Python code?

a. "1111111111"
b. "0000000000"
c. A string with some 1s and some 0s
d. The function will raise an error
Answer: Option c

6. Consider the following code snippet:

What does the code do?


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, takes list of the elements as input, 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: option b
Get the number of elements in the variable n
Iterate from 0 till n, and take integer input from the user, typecast it to integer and store in the
variable num.
Append the value stored in variable num to the list numbers.

result = sum(numbers)
average = result/n

7. What will be the output of the following Python code?

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

8. Consider the following code snippet:

What does the code do? [MSQ]


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: Options a and b
new_numbers = []
new_numbers.insert(0, 1)
# new_numbers= [1]
new_numbers.insert(0,2)
# new_numbers = [2, 1]
9. Which of the following are the examples of Social Computing/Crowd Computing:
[MSQ]
a. Wikipedia
b. Stack Exchange
c. Quora
d. Facebook
Answer: All the options are correct

10. Consider the following code snippet:

What does the code do?


a. Prints numbers from 1 to 20, replacing multiples of 3 with "Fizz", multiples of
5 with "Buzz", and multiples of both 3 and 5 with "FizzBuzz".
b. 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".
c. Prints numbers from 1 to 20, replacing multiples of 3 with "Fizz", multiples of
5 with "Buzz", and numbers divisible by both 3 and 5 with their product.
d. Prints numbers from 1 to 20, replacing multiples of 3 with "Buzz", multiples
of 5 with "Fizz", and numbers divisible by both 3 and 5 with "FizzBuzz".
Answer: option b
i=0
i%3=0 and i%5 = 0
FizzBuzz
i=1
i%3 = 1, i%5 = 1
1
i =2
2
i=3
Fizz
i=4
4
i=5
Buzz
i = 6,7,8
6
7
8
i=9
Fizz

Programming Problems

11. You are given a list marks that has the marks scored by a class of students in a

Mathematics test. Find the median marks and store it in a float variable
named median. You can assume that marks is a list of float values.

Procedure to find the median

(1) Sort the marks in ascending order. Do not try to use built-in methods.

(2) If the number of students is odd, then the median is the middle value in the sorted

sequence. If the number of students is even, then the median is the arithmetic mean of the two

middle values in the sorted sequence.

Use selection sorting algorithm.

12. Write a python program to generate a password with the following specifications:

a. Password length should be 10 characters long.

b. It must contain at least 2 upper case letters, 1 digit, and 1 special symbol.
13. Write a Python program that takes a string as input from the user. It does following

operations based on the given conditions:

a. Reverse the string if the length of the string is >4.

b. Return jumbled string if the length is <=4.

14. Write a program that generates a list containing random integers between 0 and 100.

a. Visualize the data using matplotlib line plot.


b. Compute mean, median, mode and standard deviation of the data. You can use

the sort function used in problem 11. You are not allowed to use any Python

library other than matplotlib.

c. Show mean, median and mode values on the plot.

You might also like