Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested Conditionals
#2
Hi shen123,

the following worked for me, is this the type of thing, you were thinking of ? :-

animal = ['Lion', 'Zebra', 'Warthog', 'Elephant', 'Tiger', 'Hyena']

animal = 'Warthog'

if animal == 'Lion':
        print('Meat')
elif animal == 'Zebra':
        print('Grass')
elif animal == 'Warthog':
        print('Water')
elif animal in ['Elephant', 'Tiger', 'Hyena']:
    print('Already fed!')
else:
    print('Animal not listed')

print()
If not, could you post the Full Code you have ?

Best Regards

Eddie Winch
Reply


Messages In This Thread
Nested Conditionals - by shen123 - Jul-27-2021, 07:43 AM
RE: Nested Conditionals - by eddywinch82 - Jul-27-2021, 10:45 PM
RE: Nested Conditionals - by menator01 - Jul-28-2021, 07:23 AM
RE: Nested Conditionals - by Yoriz - Jul-28-2021, 08:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Doubt about conditionals in Python. Carmazum 6 1,695 Apr-01-2023, 12:01 AM
Last Post: Carmazum
  conditionals based on data frame mbrown009 1 929 Aug-12-2022, 08:18 AM
Last Post: Larz60+
  Efficiency with regard to nested conditionals or and statements Mark17 13 3,319 May-06-2022, 05:16 PM
Last Post: Mark17
  Nested conditionals vs conditionals connected by operators dboxall123 8 3,173 Feb-18-2022, 09:34 PM
Last Post: dboxall123
  Invalid syntax using conditionals if - else jperezqu 1 2,376 Jan-13-2021, 07:32 PM
Last Post: bowlofred
  conditionals with boolean logic?? ridgerunnersjw 3 2,049 Sep-26-2020, 02:13 PM
Last Post: deanhystad
  two conditionals with intermediate code Skaperen 5 2,874 Jul-12-2020, 07:18 PM
Last Post: Skaperen
  Conditionals, while loops, continue, break (PyBite 102) Drone4four 2 3,048 Jun-04-2020, 12:08 PM
Last Post: Drone4four
  Nested Conditionals HELP absolum 4 2,837 Jul-17-2019, 06:40 PM
Last Post: absolum
  Branching and Conditionals/If statements MSL 1 1,980 Jan-26-2019, 11:52 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020