Jump to content

Python Help!

Go to solution Solved by X1XNobleX1X,
Completed with this:

line = input('Line: ')

words = line.split()

line = line.lower()

lwords = line.split()

if 'cat' in line:

  if 'cat' not in lwords:

    print('There is a hidden cat in the line.')

  else:

    if 'cat' in words:

      print('There is a small cat in the line.')

    elif 'CAT' in words:

      print('There is a big cat in the line.')

    else:

      print('There is a medium sized cat in the line.')

else:

  print('No cats here.')

Hello,

In a little trouble with my current question.

THis is what I have at the moment. 

cats = input("Line:")
catstwo = cats.split()
if "cat" in cats.lower():
  if "cat" not in catstwo:
   print("There is a hidden cat in the line.")
  else:
    if "cat" in catstwo:
       print("There is a small cat in the line.")
    elif "CAT" in catstwo:
       print("There is a big cat in the line.")
    else:
       print("There is a medium sized cat")
else:
 print("No cats here")
        
      
               
  This is what it must produce:'
  • If the word cat occurs in all lowercase letters in the line, print out: There is a small cat in the line.
  • If the word cat occurs in all uppercase letters in the line, print out: There is a big cat in the line.
  • If the word cat occurs in the line in any combination of upper and lowercase letters, print out: There is a medium sized cat in the line.
  • If the letters cat occur in the line but not as a distinct word, in any combination of upper and lowercase letters, print out: There is a hidden cat in the line.
  • Otherwise, if none of these conditions hold true, you should print out: No cats here.

Your program should work like this:

 
 
 
 
 
 
 
 
Line: There's the cat from next door.
There is a small cat in the line.
 
 

Here is another example:

 
 
 
 
 
 
 
 
Line: The CaT ran down the stairs.
There is a medium sized cat in the line.
 
 

Here is a third example:

 
 
 
 
 
 
 
 
Line: Education is very important.
There is a hidden cat in the line.
 

|CPU: Intel 5960X|MOBO:Rampage V Extreme|GPU:EVGA 980Ti SC 2 - Way SLI|RAM:G-Skill 32GB|CASE:900D|PSU:CorsairAX1200i|DISPLAY :Dell U2412M X3|SSD Intel 750 400GB, 2X Samsung 850 Pro|

Peripherals : | MOUSE : Logitech G602 | KEYBOARD: K70 RGB (Cherry MX Brown) | NAS: Synology DS1515+  - WD RED 3TB X 5|ROUTER: AC68U

Sound : | HEADPHONES: Sennheiser HD800 SPEAKERS: B&W CM9 (Front floorstanding) ,  B&W CM Center 2 (Centre) | AV RECEIVER : Denon 3806 | MY X99 BUILD LOG!

 

Link to comment
https://linustechtips.com/topic/208830-python-help/
Share on other sites

Link to post
Share on other sites

Completed with this:

line = input('Line: ')

words = line.split()

line = line.lower()

lwords = line.split()

if 'cat' in line:

  if 'cat' not in lwords:

    print('There is a hidden cat in the line.')

  else:

    if 'cat' in words:

      print('There is a small cat in the line.')

    elif 'CAT' in words:

      print('There is a big cat in the line.')

    else:

      print('There is a medium sized cat in the line.')

else:

  print('No cats here.')

|CPU: Intel 5960X|MOBO:Rampage V Extreme|GPU:EVGA 980Ti SC 2 - Way SLI|RAM:G-Skill 32GB|CASE:900D|PSU:CorsairAX1200i|DISPLAY :Dell U2412M X3|SSD Intel 750 400GB, 2X Samsung 850 Pro|

Peripherals : | MOUSE : Logitech G602 | KEYBOARD: K70 RGB (Cherry MX Brown) | NAS: Synology DS1515+  - WD RED 3TB X 5|ROUTER: AC68U

Sound : | HEADPHONES: Sennheiser HD800 SPEAKERS: B&W CM9 (Front floorstanding) ,  B&W CM Center 2 (Centre) | AV RECEIVER : Denon 3806 | MY X99 BUILD LOG!

 

Link to comment
https://linustechtips.com/topic/208830-python-help/#findComment-2836021
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×