ARGHH..um WHILE loops it think

This is the place for queries that don't fit in any of the other categories.

ARGHH..um WHILE loops it think

Postby el_manu » Mon Sep 02, 2013 11:53 am

Code: Select all
count = 0
count1 = 0
a = input("Enter line: ")
b = a[0]
while a != "":
   if a.isupper():
      count = count + 1
      a = input("Enter line: ")
   elif b.islower():
      count1 = count1 + 1
      a = input("Enter line: ")
print("The cat entered", count, "lines.")


this code has an infinte loop somewhere and doesn't work properly ...aARGHHH...

the question is a program that asks user for input until left blank...and every input entered in full capitals was written by a cat...

then at the end you say how many sentences the cat wrote
el_manu
 
Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Re: ARGHH..um WHILE loops it think

Postby Mekire » Mon Sep 02, 2013 12:25 pm

You failed to take into account words that are neither all upper or all lower. If you enter a word which has mixed case then neither of your if statements run. Aside from that though, you are over complicating the question in general.

Code: Select all
the_cat_said = []
my_input = "Start"
while my_input:
    my_input = input("Enter line: ")
    if my_input.isupper():
        the_cat_said.append(my_input)
print("The cat entered {} lines.".format(len(the_cat_said)))

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 5 guests