• Register
0 votes
25 views

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

import string

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

But I can not get the actual result. When I run this code it shows me some error :

  UUU
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

Can anyone help me to solve this thing?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes

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

You can use isupper to get an exact result:

def UpperCase(string):
    words=[charecter for charecter in string if charecter.isupper() or chatercter.isspace()]
    if len(words)==len(string):
        print('All charecters are in uppercase')
    else:
        print("All charecters are not in uppercase")

strings=['UPPER', 'CASE', 'UpperCASE', 'UPPERcase']
for x in strings:
   UpperCase(x)

You can get below result using this code:

All charecters are in uppercase

 

11 6 4
34,950 points

Related questions

0 votes
1 answer 106 views
106 views
I am new to python programming. I was trying to compare two strings, I wrote a code to compare: YourStr = "one" MyStr = "one" if YourStr = MyStr print("Two strings are same") else print("Two strings are not same") But it gives an error: File "main.py", line 4 if YourStr = MyStr ^ SyntaxError: invalid syntax Whats wrong in my code and how can I compare two string but it is not case sensitive?
asked Mar 16, 2020 LizzyM 6.1k points
1 vote
1 answer 24 views
24 views
Problem: I am beginner in pyhton programing. I have a dictionary of string and int and that is: Dictionary = { "Hola": 65, "tart" : 32, "star" : 34, "site" : 55, "pearl" : 88 } Supose I have to remove a key from this dictionary what should I do next.
asked Mar 28, 2020 LizzyM 6.1k points
0 votes
1 answer 33 views
33 views
I am new to python programming.. I was trying to check if a string is empty or whitespace in a code : Mystr= "" Yourstr = " " print ("This string is empty : ", end = "") if(not Yourstr): print ("Yes") print ("This string is empty : ", end = "") if(not Mystr): print ("No") It&rsquo;s output is : This string is empty : This string is empty : No Its not giving me actual result what can I do now?
asked Mar 16, 2020 LizzyM 6.1k points
0 votes
1 answer 3 views
3 views
Problem: I need help in this, Please help: How to check if a value is in a dictionary python
asked Mar 15 Wafa Abu Yousef 6.1k points
3 votes
1 answer 27 views
27 views
Problem: Hi all, I am trying to figure out the dictionary related problems in python. Dictionary is really fun to learn and work with. Let&rsquo;s say, I have a dictionary dict = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'} If ... needed to check every value inside the dictionary what can I do for that? So, I want to know how to check if a value is in a dictionary python?
asked Mar 24, 2020 Gavin 15.3k points
0 votes
1 answer 56 views
56 views
I wrote a code to check if a dictonary is empty or not. I wrote this code in python : def isEmpty(self, dictionary): for element in dictionary: if element: return True return False def onMessage(self, socket, message): if self.isEmpty(self.users) == False: socket.send("No ... : socket.send("ONLINE " + ' ' .join(self.users.keys())) Does my isEmpty returns true and is there any problem in my code.
asked Mar 11, 2020 LizzyM 6.1k points
1 vote
1 answer 38 views
38 views
Problem: I am new in pyhton programing language . I was trying to check if two strings are anagrams python. But I fail repitedly. The code I wrote to check if two strings are anagrams is: def IsAnagram(str1,str2): str1 = input("Enter your first string : ") ... , line 4 str1 = input("Enter your first string : ") ^ IndentationError: expected an indented block What is the problem can anyone tell?
asked Apr 2, 2020 LizzyM 6.1k points
0 votes
1 answer 22 views
22 views
Problem Hi Kodlogs, How to check if a key is in a dictionary python? Please help Thanks
asked Oct 30, 2020 hashq 1.1k points