SlideShare a Scribd company logo
For any help regarding Python Homework Help
visit : - https://www.pythonhomeworkhelp.com/,
Email :- support@pythonhomeworkhelp.com or
call us at :- +1 (315) 557-6473
Introduction To Python
Programming
Q.1. Are each of the following True or False
1.1 In Python the values of a dict must be immutable.
1.2 There exist problems that cannot be solved in Python without using either
iteration or recursion.
1.3 Floating point arithmetic behaves exactly like normal arithmetic on real
numbers.
1.4 On all inputs, a bisection search will run faster than a linear search.
1.5 Let L be a list, each element of which is a list of ints. In Python, the assignment
statement L[0][0] = 3 mutates the list L.
Solution:
1.1 FALSE. The values of keys must be immutable.
1.2 TRUE. Otherwise, the complexity of programs would be bound by the length of
the code.
1.3 FALSE. Floating point provides only an approximation to real numbers.
1.4 FALSE. It has a higher asymptotic complexity, but there can be inputs on which
it will run more slowly. Consider, for example, searching for an element that
happens to the first element of the list.
1.5 FALSE, it mutates the list at L[0].
Q.2. What does the following code print?
T = (0.1, 0.1)
x = 0.0
for i in range(len(T)):
for j in T:
x += i + j
print x
print i
Solution:
0.1
0.2
1.3
2.4
1
Q.3. What does the following code print?
def f(s):
if len(s) <= 1:
return s
return f(f(s[1:])) + s[0] #Note double recursion
print f('mat')
print f('math')
Solution:
atm
Hatm
Q.4. Implement the body of the function specified
def findAll(wordList, lStr):
"""assumes: wordList is a list of words in lowercase.
lStr is a str of lowercase letters.
No letter occurs in lStr more than once
returns: a list of all the words in wordList that contain each of the letters in
lStr exactly once and no letters not in lStr.""“
Solution:
def findAll(wordList, letters):
result = []
letters = sorted(letters)
for w in wordList:
w = sorted(w)
if w == letters: result.append(w)
return result
Q.5. The following code does not meet its specification. Correct it.
def addVectors(v1, v2):
"""assumes v1 and v2 are lists of ints.
Returns a list containing the pointwise sum of the elements in v1 and v2.
For example
addVectors([4,5], [1,2,3]) returns [5,7,3],and
addVectors([], []) returns []. Does not modify inputs."""
if len(v1) > len(v2):
result = v1
other = v2
else:
result = v2
other = v1
for i in range(len(other)):
result[i] += other[i]
return result
Solution:
insert the lines
v1 = v1[:]
v2 = v2[:]
before the first line of executable code.

More Related Content

PPTX
PPTX
Python introduction
PPTX
Introduction to python programming ( part-3 )
PPTX
Keep it Stupidly Simple Introduce Python
PPTX
Python Revision Tour.pptx class 12 python notes
PPSX
Programming with Python
PPT
mooc_presentataion_mayankmanral on the subject puthon
PPTX
Python-CH01L04-Presentation.pptx
Python introduction
Introduction to python programming ( part-3 )
Keep it Stupidly Simple Introduce Python
Python Revision Tour.pptx class 12 python notes
Programming with Python
mooc_presentataion_mayankmanral on the subject puthon
Python-CH01L04-Presentation.pptx

Similar to Introduction to Python Programming.pptx (20)

PDF
CPPDS Slide.pdf
PPTX
Perfect Python Homework Help
DOCX
CS3401- Algorithmto use for data structure.docx
PPTX
009 Data Handling class 11 -converted.pptx
PPTX
009 Data Handling class 11 -converted.pptx
PPTX
Learn more about the concepts of Data Types in Python
PPTX
python fudmentalsYYour score increaseases
PPTX
Python programming for Beginners - II
PPTX
unit1.pptx for python programming CSE department
DOCX
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ODP
Python basics
PDF
chapter1.pdf ......................................
PPTX
009 Data Handling .pptx
PDF
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
PPT
Data types usually used in python for coding
PPT
02python.ppt
PPT
02python.ppt
PDF
Python for Scientific Computing
DOCX
Python Math Concepts Book
PPTX
Basics of python 3
CPPDS Slide.pdf
Perfect Python Homework Help
CS3401- Algorithmto use for data structure.docx
009 Data Handling class 11 -converted.pptx
009 Data Handling class 11 -converted.pptx
Learn more about the concepts of Data Types in Python
python fudmentalsYYour score increaseases
Python programming for Beginners - II
unit1.pptx for python programming CSE department
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
Python basics
chapter1.pdf ......................................
009 Data Handling .pptx
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Data types usually used in python for coding
02python.ppt
02python.ppt
Python for Scientific Computing
Python Math Concepts Book
Basics of python 3
Ad

More from Python Homework Help (20)

PPTX
Python Homework Help
PPTX
Python Homework Help
PPTX
Python Homework Help
PPTX
Python Homework Help
PPTX
Python Homework Help
PPTX
Complete my Python Homework
PPTX
Introduction to Python Dictionary.pptx
PPTX
Basic Python Programming.pptx
PPTX
Introduction to Python Programming.pptx
PPTX
Introduction to Python Programming.pptx
PPTX
Introduction to Python Programming.pptx
PPTX
Introduction to Python Programming.pptx
PPTX
Introduction to Python Programming.pptx
PPTX
Introduction to Python Programming.pptx
PPTX
Python Homework Help
PPTX
Python Homework Help
PPTX
Python Programming Homework Help.pptx
PPTX
Quality Python Homework Help
PPTX
Python Homework Help
PPTX
Quality Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Complete my Python Homework
Introduction to Python Dictionary.pptx
Basic Python Programming.pptx
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
Python Homework Help
Python Programming Homework Help.pptx
Quality Python Homework Help
Python Homework Help
Quality Python Homework Help
Ad

Recently uploaded (20)

PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Basic Mud Logging Guide for educational purpose
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Cell Types and Its function , kingdom of life
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Classroom Observation Tools for Teachers
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Pre independence Education in Inndia.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O5-L3 Freight Transport Ops (International) V1.pdf
01-Introduction-to-Information-Management.pdf
O7-L3 Supply Chain Operations - ICLT Program
Basic Mud Logging Guide for educational purpose
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning
Pharmacology of Heart Failure /Pharmacotherapy of CHF
GDM (1) (1).pptx small presentation for students
Cell Types and Its function , kingdom of life
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Classroom Observation Tools for Teachers
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
102 student loan defaulters named and shamed – Is someone you know on the list?
Pre independence Education in Inndia.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx

Introduction to Python Programming.pptx

  • 1. For any help regarding Python Homework Help visit : - https://www.pythonhomeworkhelp.com/, Email :- support@pythonhomeworkhelp.com or call us at :- +1 (315) 557-6473 Introduction To Python Programming
  • 2. Q.1. Are each of the following True or False 1.1 In Python the values of a dict must be immutable. 1.2 There exist problems that cannot be solved in Python without using either iteration or recursion. 1.3 Floating point arithmetic behaves exactly like normal arithmetic on real numbers. 1.4 On all inputs, a bisection search will run faster than a linear search. 1.5 Let L be a list, each element of which is a list of ints. In Python, the assignment statement L[0][0] = 3 mutates the list L. Solution: 1.1 FALSE. The values of keys must be immutable. 1.2 TRUE. Otherwise, the complexity of programs would be bound by the length of the code.
  • 3. 1.3 FALSE. Floating point provides only an approximation to real numbers. 1.4 FALSE. It has a higher asymptotic complexity, but there can be inputs on which it will run more slowly. Consider, for example, searching for an element that happens to the first element of the list. 1.5 FALSE, it mutates the list at L[0]. Q.2. What does the following code print? T = (0.1, 0.1) x = 0.0 for i in range(len(T)): for j in T: x += i + j print x print i Solution: 0.1 0.2
  • 4. 1.3 2.4 1 Q.3. What does the following code print? def f(s): if len(s) <= 1: return s return f(f(s[1:])) + s[0] #Note double recursion print f('mat') print f('math') Solution: atm Hatm Q.4. Implement the body of the function specified def findAll(wordList, lStr):
  • 5. """assumes: wordList is a list of words in lowercase. lStr is a str of lowercase letters. No letter occurs in lStr more than once returns: a list of all the words in wordList that contain each of the letters in lStr exactly once and no letters not in lStr.""“ Solution: def findAll(wordList, letters): result = [] letters = sorted(letters) for w in wordList: w = sorted(w) if w == letters: result.append(w) return result Q.5. The following code does not meet its specification. Correct it. def addVectors(v1, v2): """assumes v1 and v2 are lists of ints. Returns a list containing the pointwise sum of the elements in v1 and v2. For example
  • 6. addVectors([4,5], [1,2,3]) returns [5,7,3],and addVectors([], []) returns []. Does not modify inputs.""" if len(v1) > len(v2): result = v1 other = v2 else: result = v2 other = v1 for i in range(len(other)): result[i] += other[i] return result Solution: insert the lines v1 = v1[:] v2 = v2[:] before the first line of executable code.