Task 4: for Loops (PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS
#!/usr/bin/python3 # Measure
some strings: words = ['cat',
'window', 'defenestrate'] for w in
words: print(w, len(w))
#!/usr/bin/python3 # Measure
some strings: words = ['cat',
'window', 'defenestrate']
for w in
words:
print(w,
len(w))
forvar in
list(range(5)): print
(var)
for letter in 'Python': # traversal of a string
sequence print ('Current Letter :', letter) print()
fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # traversal of List
sequence print ('Current fruit :', fruit)
fruits = ['banana', 'apple',
'mango'] for index in
range(len(fruits)): print
('Current fruit :', fruits[index])
print ("Good
bye!")
numbers =
[11,33,55,39,55,75,37,21,23,41,13]
fornum in numbers: if num%2 == 0:
print ('the list contains an even
number') break else: print ('the list does
not contain even number')
a = ['Mary', 'had', 'a', 'little',
'lamb'] fori in range(len(a)):
print(i, a[i])
CORRECTED PYTHON CODE:
#!/usr/bin/python3
# Measure some strings:
words = ['cat','window', 'defenestrate']
# looping every word from words list
for w in words:
print(w, len(w))
# looping by creating a list of 5 integers
for var in list(range(5)):
print (var)
# traversal of a string sequence
for letter in 'Python':
print ('Current Letter :', letter)
print()
# traversal of List sequence
fruits = ['banana', 'apple', 'mango']
# looping through item in fruits list
for fruit in fruits:
print ('Current fruit :', fruit)
fruits = ['banana', 'apple','mango']
# looping through item in fruits list using index
for index in range(len(fruits)):
print('Current fruit :', fruits[index])
print ("Good bye!")
# list of numbers
numbers = [11,33,55,39,55,75,37,21,23,41,13]
# looping through every number in the list
for num in numbers:
if num % 2 == 0:
print ('the list
contains an even number')
break
else:
print ('the list does
not contain even number')
# list of words
a = ['Mary', 'had', 'a', 'little','lamb']
# looping through every word from the list
for i in range(len(a)):
print(i, a[i])
SCREENSHOT FOR CODING:
SCREENSHOT FOR OUTPUT:
Task 4: for Loops (PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS #!/usr/bin/python3 # ...
Task 1: Calling a Function PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS Task 1: Calling a Function Defining a function gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code. Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following is an example to call the printme() function #!/usr/bin/python 3...
Below is the Graph file that needs to be modified(using Python3) : #!/usr/bin/python3 # Simple Vertex class class Vertex: """ Lightweight vertex structure for a graph. Vertices can have the following labels: UNEXPLORED VISITED Assuming the element of a vertex is string type """ __slots__ = '_element', '_label' def __init__(self, element, label="UNEXPLORED"): """ Constructor. """ self._element = element self._label = label def element(self): """ Return element associated with this vertex. """ return self._element def getLabel(self): """ Get label assigned to...