Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A)Using python 3 Rewrite the code using a for loop with an iterator: adr = \"340

ID: 2246599 • Letter: A

Question

A)Using python 3 Rewrite the code using a for loop with an iterator:

adr = "340 W 1st"

digStr = " "; ct = 0

while ct < len(adr):

ch = adr[ct]

if ch.isdigit():

digit = int(ch); digStr += str(digit)

ct += 1

print (digStr)

B) Write Python code that asks the user to enter a sentence. It should print the number of capital letters in the sentence.

“””# of words with > 5 chars “””
sent = input(“Enter a sentence”); ct=0 wordList = sent.split(“ “)
for word in wordList:
if len(word) >= 5: ct += 1

print(ct)

Explanation / Answer

adr = "340 W 1st"
digStr = " ";
for ch in adr:
    if ch.isdigit():
        digit = int(ch);
        digStr += str(digit)

print (digStr)

-----------------------------------------------------------------------------------------------------------------

sent = raw_input("Enter a sentence: ");
ct=0
for ch in sent:
    if ch.isupper():
        ct = ct + 1
print(ct)