Sei sulla pagina 1di 6

College of Computing Education

3rd Floor, DPT Building


Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

[ Laboratory No. 2.4: Count]


Objectives:
1. To know the loop construct in Python Programming
2. To create a program that take advantage of the loop mechanisms

Materials:
1. PC or Laptop
2. Python Package Development Kit
3. Pycharm or any IDE

Background:

…Continuation

@Split by whitespace. By default, split() takes whitespace as the delimiter.

Output:

@Split + maxsplit. An example by first 5 whitespaces only.

Output:

IT5/L Martzel P. Baste|Page 1


College of Computing Education
3rd Floor, DPT Building
Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

@Split by #

More on String functions

Instructions:

IT5/L Martzel P. Baste|Page 2


College of Computing Education
3rd Floor, DPT Building
Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

1. Create class Count[Surname]


2. Problem Scenario

Create a program that accepts string value in sentence with mix of numbers and special characters.
Afterwards, the program will then count how many special characters, total alphabets,
consonants and vowels, total number of digits, odd and even digits.

3. Input

Input consist of a string input, a statement or sentence with mix of alphanumeric, special
characters.

4. Constraints

Input must NOT be null or empty. Whitespaces such as space and tabs are included as special
characters.

5. Output

Your program should count/output the following:

special characters
total alphabets
consonants
vowels
total number of digits
odd
even

6. Source Codes

vowel =
["a","e","i","o","u"]

o, e, a, s, c, v, d= 0, 0, 0, 0, 0, 0, 0

string=input("Enter String: ")

IT5/L Martzel P. Baste|Page 3


College of Computing Education
3rd Floor, DPT Building
Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

for x in range(0, len(string)):

if string[x].isalpha():

a+=1 #Alphabet counter

if string[x] in vowel:

v += 1 #Vowel counter

if string[x] not in vowel and string[x].isalpha():

c += 1 #Consonant counter

if string[x].isspace() is False and


string[x].isalpha() is False and string[x].isdigit() is
False:

s += 1 #Special Character counter

if string[x].isdigit():

d+=1 #Digit counter

num = int(string[x])

if num % 2 == 0: e += 1 #Even counter

else: o += 1 #Odd counter

print("Special Characters: "+str(s))

print("Total Alphabet: " + str(a))

print("Consonants: "+str(c))

print("Vowels: "+str(v))

print("Digits: "+str(d))

print("Even: "+str(e))

print("Odd: "+str(o))

IT5/L Martzel P. Baste|Page 4


College of Computing Education
3rd Floor, DPT Building
Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

7. Sample Input/Output

NOTE: Provide a screenshot and describe your observation for each action you performed based on
the item below:

 Input valid value for string

 Empty value for string

IT5/L Martzel P. Baste|Page 5


College of Computing Education
3rd Floor, DPT Building
Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

 Try to implement split() in your program using any character.

8. Submit your file with filename convention: Count[Surname]

Rules:

1. Each laboratory activity has time limit of 1:30 minutes and is due on
the day depending on the level of difficulty or constraints.
2. Each activity will only last every after 3 days and has deduction of 10
points every day from the day it was given.

IT5/L Martzel P. Baste|Page 6

Potrebbero piacerti anche