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

Tutorial 8 Solution

This document contains a tutorial assignment with 17 questions on Python programming concepts like strings, functions, lists, loops etc. The questions cover topics like string permutations, keyword arguments in functions, type conversion, string slicing, counting substrings etc. and students are expected to write the code and predict the output.

Uploaded by

ritz0874
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)
13 views

Tutorial 8 Solution

This document contains a tutorial assignment with 17 questions on Python programming concepts like strings, functions, lists, loops etc. The questions cover topics like string permutations, keyword arguments in functions, type conversion, string slicing, counting substrings etc. and students are expected to write the code and predict the output.

Uploaded by

ritz0874
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

Course- BTech Type- Core

Course Code- CSET101 Course Name- ComputationalThinking and


Programming
Year- 2023 Semester- odd
Date- Batch- ALL

Tutorial Assignment: 8 Solutions

Q1.Write a python program to find out all permutation of given string. Take input without any
space.

from itertools import permutations

def allPermutations(str):

# Get all permutations of string 'ABC'


permList = permutations(str)

# print all permutations


for perm in list(permList):
#print(permList)
print (''.join(perm))

# Driver program
if __name__ == "__main__":
str = 'ABC'
allPermutations(str)

Q2.What is the output of given code-

def fun(**kwargs):
for key, value in kwargs.items():
print("%s == %s" % (key, value))

fun(a='bennett', b='university', c='greater noida')

output
Q3.

def myAtoi(string):
res = 0

# Iterate through all characters of


# input string and update result
for i in range(len(string)):
res = res * 10 + (ord(string[i]) - ord('0'))

return res

string = "89789"
print(type(string))
print(string)
new_no = myAtoi(string)
print(type(new_no))
print(new_no)

Q4. What will be the output of the following code.


string1 = "python"
list_string = ["computer", "python", "prog"]

print(list_string [1] == string1)


print(list_string [1] is string1)

Output-

Q5. Predict the output of the following code:

string1 = "welcome tothe thetothe World of the Python the"


substring1 = "the"
print(string1.count(substring1, 15))

Output- 3

Q6. Predict the output of the following code:

string1 = 'Python'
print (string1[:2] + ' Programming')

Output- Py Programming
Q7. What will be the output of the following code?

string1 = 'Python'
string2 = 'Prog'
string3 = 2 * (string1 + string2)
print(string3)
if "onPr" in string3:
print("Python is cool")
else:
print("Python is tough")

Output-

Q8. Find out the error in the following code

def display(*param):
for i in param:
print(i)

display(name="Aarav", age="15")

Output-

There should be double asterisk sign in the formal parameter

Q9. Find out the error in the following code:

def fn(x):
temp=100
return x + temp
fn(500)
print(temp)

Output-

temp is a local variable defined inside the function, so it is not


accessible outside the function. To access it outside the function temp
should be declared as global variable.

Q10. What will be the output of the following code?


output

Q11. What will be the output of the following code? If there is any error, identify it.

string1="Bennett"
print(string1)
string2=ord(string1)
print(string2)

Output-

ord() function can take only a character as an input but here in the code string has been passed.

Q12. What will be the output of the following code?

def fn(name = "Dravid"):


print("My favourite cricketer is " + name)
fn("Sachin")
fn()
fn("Sehwag")

Output-

Q13. Predict the output of the following code.

def my_function(list1):
for i in list1:
print(i)
colors = [("red", '1'),("green", '2'),("orange",'3')]
my_function(colors)

Output-

Q14. Predict the output of the following code:

string1 = 'pyython'
print(string1[::-1][::-5])
print(string1[::5])
print(string1[0] + string1[-1])
print(string1[::-1][-1] + string1[len(string1)-1])
print(string1[::-5])
Q15. Predict the outcome of the following:

(A)
name = 'Nina'
pi = 3.14
food = 'pie'
message = (
f"Hello, my name is {name}. "
f"I can calculate pi to two places: {pi:4.3}. "
f"But I would rather be eating {food}.")
output

B)

Q16. Predict the outcome of the following:

def vowel(text):
vowels = "aeiuoAEIOU"
print(len([letter for letter in text if letter in vowels]))
print([letter for letter in text if letter in vowels])

vowel('Welcome India')

Q17. Predict the outcome of following:

n = 10
row = "*"
while n > 0:
print(" " * n + row)
row += "**"
n -= 1
*
***
*****
*******
*********
***********
*************

You might also like