Snippets Collections
Write a function named only_ints that takes two parameters. Your function should return True if both parameters are integers, and False otherwise.

For example, calling only_ints(1, 2) should return True, while calling only_ints("a", 1) should return False.
ChatGPT
ChatGPT
Here's a Python function named only_ints that checks if both parameters are integers:

python
Copy code
def only_ints(param1, param2):
    return isinstance(param1, int) and isinstance(param2, int)

# Example usage:
print(only_ints(1, 2))   # Output: True
print(only_ints("a", 1))  # Output: False

Copy and Save

Share

Ask Copilot

This function uses the isinstance() function to check if both parameters are of type int. If both are integers, it returns True; otherwise, it returns False.
star

Sat Mar 30 2024 03:48:43 GMT+0000 (Coordinated Universal Time) https://chat.openai.com/c/18771bc8-88df-4de4-855f-8c650298a69e

#python #python_functions

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension