Featured Posts

CS50 Python , Nutrition Facts Table

Image
Nutrition Facts: Python Practice for Beginners Nutrition Facts Table for Python Practice Welcome to this comprehensive guide for Python beginners! If you are learning how to work with lists, dictionaries, and loops, this post will help you build practical skills using a real-world example: nutrition facts for fruits. Understanding how to organize and manipulate data is a key part of programming, and this exercise will give you hands-on experience. Below is a sample table of fruits and their calorie values, formatted as a Python list of dictionaries. This structure is ideal for coding exercises, projects, or even building your own nutrition calculator. You can expand this list, add new fruits, or use it as a foundation for more advanced Python tasks. Python List of Dictionaries Example: fruits = [ {'name': 'Apple', 'calories': 130}, {'name': 'Avocado', 'calories': 50}, {'name': 'Banana', 'ca...

Python 3.2.1.11 LAB: The continue statement - the Pretty Vowel Eater

 3.2.1.11 LAB: The continue statement - the Pretty Vowel Eater

the Pretty Vowel Eater
The Pretty Vowel Eater

If you're taking PCAP - Programming Essentials In Python , you may have encountered this question in  3.2.1.11 LAB: The continue statement - the Pretty Vowel Eater.

Objectives

Familiarize the student with:

using the continue statement in loops;

modifying and upgrading the existing code;

reflecting real-life situations in computer code.

Scenario

Your task here is even more special than before: you must redesign the (ugly) vowel eater from the previous lab (3.1.2.10) and create a better, upgraded (pretty) vowel eater! Write a program that uses:

a 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;

assign the uneaten letters to the word_without_vowels variable and print the variable to the screen.

Look at the code in the editor. We've created word_without_vowels and assigned an empty string to it. Use concatenation operation to ask Python to combine selected letters into a longer string during subsequent loop turns, and assign it to the word_without_vowels variable.

Test your program with the data we've provided for you.

Test data

Sample input: Gregory

Expected output:

GRGRY

Sample input: abstemious

Expected output:

BSTMS

Sample input: IOUEA

Expected output:

Solution Code

word_without_vowel = ""
user_word = input("Please Enter a Word: ").upper()
#vowels A, E, I, O, U
for letter in user_word:
    if letter == "A":
        continue
    elif letter == "E":
        continue
    elif letter == "I":
        continue
    elif letter == "O":
        continue
    elif letter == "U":
        continue
    
    else:
        word_without_vowel += letter
        
print(word_without_vowel)

In below video, we will see how for loop works. We started with an empty variable word_without_vowel to use it later to combine the letters which are NOT VOWELS. It checks each condition with the statements inside the block. If True then the condition is exempted/passed

If letter == "A":

      continue

This means, if the letter equals "A", the letter is passed and not shown

A new thing which is word_witout_vowel += letter which adds or combines the letter which has not exempted/not vowels to be printed in the console as one word


 
=================================================================================

Follow the Python page on the Blog to be the first to know

Comments

Popular posts from this blog

فرصتك للدراسة في ألمانيا: منحة ممولة بالكامل لطلاب الدراسات العليا

How to Deactivate Screen Reader in Kali Linux

Murphy's Law: Expect the Unexpected

Data Analysis Roadmap 2026: From Excel Lover to Python-Powered Analyst

Python 3.2.1.14 LAB: Essentials of the while loop