Answer:
See Explanation
Explanation:
Required:
Use for and while loop for the same program
<u>(1) String Cleaner</u>
#For Loop
name = "I am Sam"
result = ""
<em>for i in range(0, len(name)): </em>
<em> if name[i]!= 'a': </em>
<em> result = result + name[i]
</em>
print(result)
#While Loop
name = "I am Sam"
result = ""
<em>i = 0
</em>
<em>while i < len(name):
</em>
<em> if name[i]!= 'a': </em>
<em> result = result + name[i]
</em>
<em> i+=1
</em>
print(result)
<u>(2): Common Divisor</u>
#For Loop
num1 = 528
num2 = 60
div = num2
if num1 > num2:
div = num1
<em>for i in range(2,div):</em>
<em> if num1%i == 0 and num2%i==0:</em>
<em> print(i,end = " ")</em>
print()
#While Loop
num1 = 528
num2 = 60
div = num2
if num1 > num2:
div = num1
i = 2
<em>while i <div:</em>
<em> if num1%i == 0 and num2%i==0:</em>
<em> print(i,end = " ")</em>
i+=1
The iterates statements show the difference in the usage of both loops.
For the for loop, the syntax is:
<em>for [iterating-variable] in range(begin,end-1)</em>
<em>-------</em>
<em>---</em>
<em>--</em>
<em />
For the while loop, the syntax is:
<em>while(condition)</em>
<em>-------</em>
<em>---</em>
<em>--</em>