Python Forum
Have function reject bad argument when argument is called by another function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Have function reject bad argument when argument is called by another function?
#5
Please, use the same thread for same issues.

Check this implementation:

x = {"F": "Fluorine", "Cl": "Chlorine"}
y = {"O": "Oxygen"}


def hal(target_dict, key):
    try:
        # This will raise KeyError if not found
        print(target_dict[key])
    except KeyError:
        print(f'{key}: KeyError')


def acc(target_dict, key):
    try:
        # This will raise KeyError if not found
        print(target_dict[key])
    except KeyError:
        print(f'{key}: KeyError')


def is_halogen_bond(halogen, acceptor):
    hal(x, halogen)
    acc(y, acceptor)


user_key1 = input('Enter key 1: ')
user_key2 = input('Enter key 2: ')

while user_key1 != 'exit' and user_key2 != 'exit':
    is_halogen_bond(user_key1, user_key2)
    user_key1 = input('Enter key 1: ')
    user_key2 = input('Enter key 2: ')
Reply


Messages In This Thread
KeyError, Input loop - by jobroinc - Jul-19-2018, 11:02 PM
RE: KeyError, Input loop - by gontajones - Jul-19-2018, 11:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: Diagram.render() takes 1 positional argument but 2 were given sachin1361 0 381 Apr-23-2024, 06:39 AM
Last Post: sachin1361
  501 Server cannot accept argument anna17 0 358 Apr-11-2024, 01:08 AM
Last Post: anna17
  Django "Unexpected Keyword Argument 'min_value'" AstralWeeks 0 409 Mar-27-2024, 04:56 AM
Last Post: AstralWeeks
  File is not being created with 'w' argument CAD79 3 608 Mar-14-2024, 12:05 PM
Last Post: snippsat
  The function of double underscore back and front in a class function name? Pedroski55 9 969 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  __init__() got multiple values for argument 'schema' dawid294 4 3,383 Jan-03-2024, 09:42 AM
Last Post: buran
  mutable argument in function definition akbarza 1 615 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  Multiple variable inputs when only one is called for ChrisDall 2 584 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  Strange argument count error rowan_bradley 3 873 Aug-06-2023, 10:58 AM
Last Post: rowan_bradley
  Invalid argument: 'images\x08ackground.jpg' CatBall 4 1,168 Jun-19-2023, 09:28 AM
Last Post: CatBall

Forum Jump:

User Panel Messages

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