Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise 1 python. #8

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Exercise 1 python. #8

wants to merge 11 commits into from

Conversation

github-actions[bot]
Copy link

Description

Added some comments explaining the code.

Fixed the consonant printing.

Improved the message that is printed out.

Tested with the following strings:

abcdefghijklmnopqrstuvwxyz
Welcome to the Jungle 1234

Fixes issue

Fixes #7 python

for letter in text:
if letter not in vowels:
print("consonant", letter)
num += text.lower().count(letter)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing num to num1 can differentiate it from the num used for identifying the vowels.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, copying the code used to count the vowels and then changing the vowels out for consonants may be an easier fix:

def num_vowels(text):
    """Return the number of vowels in string."""
    vowels = "aeiouy"
    num = 0
    for v in vowels:
        num += text.lower().count(v)        
    return num


"""Return the number of consonants in string."""

def num_consonants(text):
    consonants = "bcdfghjklmnpqrstvwxz"
    num1 = 0
    for c in consonants:
           num1 += text.lower().count(c)
    return num1
    
text = str(input("Enter a sentence: "))

print("Number of vowels", num_vowels(text))
print("Number of consonants", num_consonants(text))



@sanyatonwu
Copy link
Owner

Tested with the following strings:

abcdefghijklmnopqrstuvwxyz
Welcome to the Jungle 1234

changed 'vowels' to 'consonants'
print the values of interest for vowels and consonants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

python: Exercise 1
2 participants