• Register
1 vote
19 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
2 answers 21 views
21 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 23 views
23 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 13.2k points
0 votes
1 answer 14 views
14 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 21 views
21 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 22 views
0 votes
0 answers 31 views
31 views
I saw this code to find difference between diagonal sums of a square matrix. #!/bin/python3 import math import os import random import re import sys def diagonalDifference(arr): d1=0 d2=0 a=n-1 print(arr[1][1]) for i in range(0,n): d1+=arr[i][i] ... ['OUTPUT_PATH'], 'w') with fptr = sys.stdout, the output shows no difference. What then is the difference between functions of these two statements?
asked Oct 29, 2020 psandprop 2.4k points
0 votes
1 answer 8 views
8 views
Problem: I have a list of arbitrary length and I need to split it into chunks of the same size and process it. There are some obvious ways to do this, like keeping a counter and two lists, and when the second list is full, add it to the first ... of any length, for example using generators. I've searched for something useful in itertoolsbut couldn't find anything useful. I may have missed this.
asked Dec 23, 2020 sasha 13.2k points
0 votes
1 answer 7 views
7 views
Solve this question.
asked Jan 22 TeamScript 13.5k points
0 votes
1 answer 24 views
0 votes
1 answer 39 views
39 views
I got a list of numbers in the range 0-1023. I want to convert them to integers such that 1023 maps to -1, 1022 maps to -2 etc.. while 0, 1, 2, ....511 remain unchanged. I came up with this: def convert(x): return (x - 2**9) % 2**10 - 2**9 is there a more better way?
asked Oct 29, 2020 psandprop 2.4k points