Instructions:
- Open a new python file.
- Print only consonants from a given text.
motivation = "Over? Did you say 'over'? Nothing is over until we decide it is! Was it over when the Germans bombed " \ "Pearl Harbor? Hell no! And it ain't over now. 'Cause when the goin' gets tough...the tough get goin'! " \ "Who's with me? Let's go!" output = "" for letter in motivation: if letter.lower() in 'bcdfghjklmnpqrstvwxyz': output += letter print(output) - However, this example can also be completed by using a
continueaction. If the condition is met, then thecontinueadvances the program to the next stage.motivation = "Over? Did you say 'over'? Nothing is over until we decide it is! Was it over when the Germans bombed " \ "Pearl Harbor? Hell no! And it ain't over now. 'Cause when the goin' gets tough...the tough get goin'! " \ "Who's with me? Let's go!" output = "" for letter in motivation: if letter.lower() not in 'bcdfghjklmnpqrstvwxyz': continue else: output += letter print(output) - Conversely, the
breakaction halts the program when the condition is met. For instance, what if we wanted to display all of the letters until the first instance of a non-letter? Abreakcan be used to end the loop once the condition is met.motivation = "Over? Did you say 'over'? Nothing is over until we decide it is! Was it over when the Germans bombed " \ "Pearl Harbor? Hell no! And it ain't over now. 'Cause when the goin' gets tough...the tough get goin'! " \ "Who's with me? Let's go!" output = "" for letter in motivation: if letter.lower() not in 'abcdefghijklmnopqrstuvwxyz': output += letter else: break print(output) - Update the log file with what you have learned today.