Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
condensing try except
#7
I don't understand your objection. One can ask the user to input 3 different probabilities by calling proba_input() 3 times
for i in range(3):
    qux = proba_input('Give me the {}-th probability: '.format(i))
The line with partial is only a way to define a new callable (proba_input) by specifying two arguments for typed_input.

Consider the following example
>>> def is_multiple_of(a, b):
...     return b % a == 0
... 
>>> is_multiple_of(5, 15)
True
>>> is_multiple_of(5, 14)
False
>>> from functools import partial
>>> is_even = partial(is_multiple_of, 2)
>>> is_even(14)
True
>>> is_even(13)
False
>>> is_even(12)
True
>>> is_even(9)
False
Reply


Messages In This Thread
condensing try except - by mepyyeti - Jan-18-2018, 06:39 AM
RE: condensing try except - by metulburr - Jan-18-2018, 06:47 AM
RE: condensing try except - by Gribouillis - Jan-18-2018, 08:15 AM
RE: condensing try except - by mepyyeti - Jan-18-2018, 05:20 PM
RE: condensing try except - by Gribouillis - Jan-18-2018, 06:20 PM
RE: condensing try except - by mepyyeti - Jan-26-2018, 10:19 PM
RE: condensing try except - by Gribouillis - Jan-26-2018, 11:13 PM

Forum Jump:

User Panel Messages

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