Answer to Question #188284 in Python for Hsnnsn

Question #188284

Using while loop and If statements, print all the letters in the following string except for the letter ‘g’ and ‘o’. (5 marks)

‘goodbyemybaloon’

Hint: use continue keyword. Continue and Break are keywords to control the flow of a loop. Continue keyword returns the control to the beginning of the loop. Now try using the break keyword and see what happens. Expain your findings.


1
Expert's answer
2021-05-02T17:48:02-0400
user_str = 'goodbyemybaloon'
i = 0
while True:
    i += 1
    if i > len(user_str)-1:
# the operator break exits the loop
        break
    if user_str[i] == 'g' or  user_str[i] == 'o':
# skips subsequent actions if the condition is not met
        continue
# printing characters on one line without a separator
    print(user_str[i],end='',sep='') 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS