Question

Task 4: for Loops (PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS #!/usr/bin/python3 # ...

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])

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

# ! /usr/bin/pythons # Mea3ure 30me 3tring3 : words -[cat, window, defenestrate] # looping every word from words list fo

SCREENSHOT FOR OUTPUT:

cat 3 window 6 defenestrate 12 0 1 2 3 4 Current Letter P Current Letter : y Current Letter: t Current Letter h Current Lette

Add a comment
Know the answer?
Add Answer to:
Task 4: for Loops (PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS #!/usr/bin/python3 # ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Task 1: Calling a Function PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS Task...

    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...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT