I have written the Python code to count the number of Capital letters in any given argument, but it gives the outcome of 0 indexes no matter what is given for input. For example: for 'Hello', it returns 1 0 Which is correct, but it then gives incorrect answers after:
'Hello World. Its a great day!'
3 <- expected 3 <- output
19 <- expected 0 <- output
'aAe_0Ia eIaoeUYQ!'
6 <- expected 6 <- output
57 <- expected 0 <- output
Here's my code:
import sys
sent = sys.argv[1:]
count = 0
for i in str(sent):
if i.isupper():
count = count + 1
print(count)
s = str(sys.argv[1:])
def c_upper(s):
upper = 0
return upper
for char in s:
if char.isupper():
upper += 1
print(c_upper(sys.argv[1:]))