• Register
1 vote
28 views

Problem:

I am new to python programming I was trying to check if a letter is lowercase in python. I wrote some code to check this statement :

import string

def LowerCase(s_str):
    for x in s_str:
        if x not in string.LowerCase:
            return False
    return True

But it always throw error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'UUU' is not defined
  LoWWE*CAse
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'LoWWE' is not defined

What should I do now?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote

Answer:

The error you are having beacuse your strings are not defined .

You can use islower to get an exact result:

def LowerCase(string):
    words=[charecter for charecter in string if charecter.islower()]
    if len(words)==len(string):
        print('All charecters are in lowercase')
    else:
        print("All charecters are not in lowercase")

strings=['LoweR', 'CASE', 'UpperCASE', 'LOWERcase']
for x in strings:
   LowerCase(x)

Hope this may help you.

11 6 4
34,950 points

Related questions

0 votes
1 answer 4 views
4 views
Problem: I need to print a '%' sign using string formatting,please show me how to di it .
asked Apr 23 zayed1 58.7k points
0 votes
1 answer 4 views
4 views
Question: I have a Python script that needs to execute an external program, but for some reason fails. If I have the following script: import os; os.system("C:\\Temp\\a b c\\Notepad.exe"); raw_input(); Then it fails with the following error: 'C:\ ... . With or without a parameter to Notepad here, it fails with the error message The filename, directory name, or volume label syntax is incorrect.
asked Apr 12 Atik03 26.5k points
0 votes
1 answer 7 views
7 views
Problem: I have a Python script that needs to execute an external program, but for some reason fails. If I have the following script: import os; os.system("C:\\Temp\\a b c\\Notepad.exe"); raw_input(); Then it fails with the following error: 'C:\Temp\ ... Notepad.exe'"); raw_input(); Note the swapped single/double quotes. With or without a parameter to Notepad here, it fails with the error message.
asked Apr 10 Atik03 26.5k points
0 votes
1 answer 9 views
9 views
Problem: How to solve this error: How do I list all files of a directory in python ?
asked Mar 19 Wafa Abu Yousef 6.1k points
0 votes
2 answers 33 views
33 views
How can I list all files of a directory in Python and add them to a list ?
asked Oct 24, 2020 psandprop 2.4k points
0 votes
1 answer 27 views
27 views
Problem: When removing a key from a dictionary, I use: if 'key' in myDict: del myDict['key'] Is there a one-line way to do this?
asked Dec 30, 2020 sasha 16.2k points
0 votes
1 answer 25 views
25 views
Why can't I perform arithmetic operations on a set. For example: {a+b} * c returns an error. When we try to do [a+b]*c, it returns a list. For instance: [4+5]*6 returns [9, 9, 9, 9, 9, 9]. But the same is not the result for the set. Why?
asked Sep 15, 2020 Marivoke 530 points
0 votes
1 answer 3 views
3 views
Question: I am having trouble writing a program to repeat this program. I want to ask them if they want to repeat (yes or no). If they say yes it repeats the whole program. This is what I have so far: sentence=input("Please enter sentence(s)") words = sentence.split() ... sentence: if x in "!?.": counter=counter+1 print("There is "+str(counter)+" sentences and " + str(number_of_words) + " words")
asked Apr 12 Atik03 26.5k points
0 votes
1 answer 18 views
18 views
Problem: I am working on a Car Parking management system in which I do need to save car data in a file and then also need to read out that data as well
asked Oct 2, 2020 SapperIt 1.2k points
0 votes
1 answer 2 views
2 views
Problem: Does anyone know the solution of it? So kindly let me know .. how do i convert awk to python
asked Apr 7 Ifra 34.7k points