WHILE loops it think

This is the place for queries that don't fit in any of the other categories. 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
Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Re: 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():
print("The cat entered {} lines.".format(len(the_cat_said)))

New Users, Read This
  • Use code tags when posting code.
  • Include any errors with your post (in code tags).
  • Describe your problem; not your chosen solution.
  • Make examples the minimum length to demonstrate your issue.
User avatar
Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 6 guests