Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Conditional evaluation
#8
It seems that you inverted the condition implied by your first post! You could also try something like
>>> a1, b1 = 140.2, 6543.5
>>> silos1a = b1 - a1 - bool(b1 > a1) * 6553.5
>>> print(f'Расход: {silos1a:.1f}')
Расход: -150.2
This amounts to using bool() as a programmatic version of the Iverson bracket used by mathematicians.
Reply


Messages In This Thread
Conditional evaluation - by stsxbel - May-31-2021, 01:28 AM
RE: Conditional evaluation - by perfringo - May-31-2021, 06:00 AM
RE: Conditional evaluation - by stsxbel - May-31-2021, 07:43 AM
RE: Conditional evaluation - by Gribouillis - May-31-2021, 09:07 AM
RE: Conditional evaluation - by stsxbel - Jun-03-2021, 03:58 AM
RE: Conditional evaluation - by snippsat - Jun-03-2021, 04:38 AM
RE: Conditional evaluation - by stsxbel - Jun-13-2021, 06:56 PM
RE: Conditional evaluation - by Gribouillis - Jun-13-2021, 08:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  UndefinedEnvironmentName: 'extra' does not exist in evaluation environment EarthAndMoon 3 1,707 Oct-09-2023, 05:38 PM
Last Post: snippsat
  Evaluation of two different list in python? go127a 8 3,659 Apr-22-2019, 12:49 PM
Last Post: snippsat
  list evaluation go127a 2 2,483 Apr-12-2019, 11:13 AM
Last Post: DeaD_EyE
  operand evaluation order? insearchofanswers87 2 2,850 Sep-26-2018, 07:51 PM
Last Post: insearchofanswers87
  Recursive evaluation in parsley parser mqnc 0 2,591 Apr-13-2018, 09:02 PM
Last Post: mqnc
  Learning Python, newbie question about strings and evaluation new_learner_999 13 5,999 Feb-18-2018, 03:01 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