Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested Conditionals
#4
Setting already_fed to False and animal to 'Warthog', "Water" is printed, I'm not sure how you ended with result as 'Already fed!'.
already_fed = False
animal = 'Warthog'

if already_fed:
    print('Already fed!')
else:
    if animal == 'Lion':
        print('Meat')
    elif animal == 'Zebra':
        print('Grass')
    else:
        print('Water')
Output:
Water
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,653 Apr-01-2023, 12:01 AM
Last Post: Carmazum
  conditionals based on data frame mbrown009 1 923 Aug-12-2022, 08:18 AM
Last Post: Larz60+
  Efficiency with regard to nested conditionals or and statements Mark17 13 3,247 May-06-2022, 05:16 PM
Last Post: Mark17
  Nested conditionals vs conditionals connected by operators dboxall123 8 3,118 Feb-18-2022, 09:34 PM
Last Post: dboxall123
  Invalid syntax using conditionals if - else jperezqu 1 2,358 Jan-13-2021, 07:32 PM
Last Post: bowlofred
  conditionals with boolean logic?? ridgerunnersjw 3 2,021 Sep-26-2020, 02:13 PM
Last Post: deanhystad
  two conditionals with intermediate code Skaperen 5 2,836 Jul-12-2020, 07:18 PM
Last Post: Skaperen
  Conditionals, while loops, continue, break (PyBite 102) Drone4four 2 3,008 Jun-04-2020, 12:08 PM
Last Post: Drone4four
  Nested Conditionals HELP absolum 4 2,817 Jul-17-2019, 06:40 PM
Last Post: absolum
  Branching and Conditionals/If statements MSL 1 1,973 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