smartphone_brand = ‘Samsung Galaxy S20’ Write a program to find the number of uppercase, lowercase, and numbers in the value assigned to the variable smartphone_brand above. Make sure to use the loop concept to answer the question.
#!/usr/bin/env python
import string
smartphone_brand = 'Samsung Galaxy S20'
num_upper = 0
num_lower = 0
num_digit = 0
for ch in smartphone_brand:
if ch in string.ascii_lowercase:
num_lower += 1
elif ch in string.ascii_uppercase:
num_upper += 1
elif ch in string.digits:
num_digit += 1
print(f'Threre are {num_upper} uppercase, {num_lower} lowercase and {num_digit} digit')
Comments
Leave a comment