Space for google add

Problem Statement to understand Concept of Break and continue loop




Problem statement:-

Design a program that uses a while loop and continuously asks the user to enter a word unless the user enters "chupacabra" as the secret exit word, in which case the message "You've successfully left the loop." should be printed to the screen, and the loop should terminate.
Don't print any of the words entered by the user. Use the concept of conditional execution and the break statement.

Program solution:

a = "chupacabra"
b = input()
while True:
   
if a != b:
        b =
input()
   
else:
       
print("You've successfully left the loop.")
       
break

 

Problem Statement : 

The continue statement is used to skip the current block and move ahead to the next iteration, without executing the statements inside the loop.

It can be used with both the while and for loops.

Your task here is very special: you must design a vowel eater! Write a program that uses:

  • for loop;
  • the concept of conditional execution (if-elif-else)
  • the continue statement.

Your program must:

  • ask the user to enter a word;
  • use user_word = user_word.upper() to convert the word entered by the user to upper case; we'll talk about the so-called string methods and the upper() method very soon - don't worry;
  • use conditional execution and the continue statement to "eat" the following vowels A, E, I, O, U from the inputted word;
  • print the uneaten letters to the screen, each one of them on a separate line.
Problem Solution : -

·      # Prompt the user to enter a word
# and assign it to the user_word variable.
user_word = input()
user_word = user_word.upper()
for letter in user_word:
   
if letter not in 'AEIOU':
       
print(letter)
   
else:
       
continue
   
# Complete the body of the for loop.

 

 

Post a Comment

0 Comments