Question
in python
A. Define a function called contains_only_integers() that takes a tuple, returns True if all the items in the tuple are integ
0 0
Add a comment Improve this question Transcribed image text
Answer #1

hem tin 1- def contains_only_integers(a): for one in a: # looping through each element if not isinstance (one, int): # if it

CODE

def contains_only_integers(a):
for one in a: # looping through each element
if not isinstance(one, int): # if it is not an integer
return False # returning false immediately
return True # otherwise it comes here to return True

print(contains_only_integers((3, 5, 17, 257, 65537)))
print(contains_only_integers((-1,)))
print(contains_only_integers(()))
print(contains_only_integers((2.0, 4.0)))
print(contains_only_integers((8, 4, "2", 1)))


--------------------------------------
Hit the thumbs up if you are fine with the answer. Happy Learning!

Add a comment
Know the answer?
Add Answer to:
in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple

    1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...

  • can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp,...

    can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp, that is passed a file name and a metal alloy's formula unit structure*". The file will contain metal elements and their properties. The function will return a tuple of the element from the formula with the lowest melting point and that melting point Write a second function, molform, that will be called by the first function, to take the metal alloy's...

  • Write a Python function called more() that takes three string inputs and outputs a string Formally,...

    Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...

  • In Python 3 Write code to define a function that uses three arguments, and returns a...

    In Python 3 Write code to define a function that uses three arguments, and returns a result. The function returns True if the first argument is more than or equal to the second argument and less than or equal to the third argument, otherwise it returns False.

  • IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns...

    IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].

  • Python problem. 3. (6 pts) Define the following four sorting functions: each takes an argument that...

    Python problem. 3. (6 pts) Define the following four sorting functions: each takes an argument that is a list of int or str or both values (otherwise raise an AssertionError exception with an appropriate error message) that will be sorted in a different way. Your function bodies must contain exactly one assert statement followed by one return statement. In parts a-c, create no other extra/temporary lists other than the ones returned by calling sorted. a. (2 pts) Define the mixed...

  • I am using Python 3.5.2 2. Create a function called is_interesting that, given a string, returns...

    I am using Python 3.5.2 2. Create a function called is_interesting that, given a string, returns the Boolean value True if the number of vowels (a e i o u) in the string is a prime number (assume that the strings are always passed as lower-case letters to simplify). The function header should be as follows: def is_interesting(a_string) For example is_interesting(“yien”) returns True, is_interesting(“wang”) returns False

  • Assume that L is a list of Boolean values, True and False. Write a function longestFalse(L)...

    Assume that L is a list of Boolean values, True and False. Write a function longestFalse(L) which returns a tuple (start, end) representing the start and end indices of the longest run of False values in L. If there is a tie, then return the first such run. For example, if L is False False True False False False False True True False False 0 1 2 3 4 5 6 7 8 9 10 then the function would return...

  • Write the function deep_contains. It takes as input a number and a list. That list might...

    Write the function deep_contains. It takes as input a number and a list. That list might contain lists as elements, and those lists might contain lists, etc. The deep_contains' function should return a Boolean indicating whether the number is contained inputted list, or a sublist of it, or a sublist of that, and so forth. For example: deep_contains (3, (1,3,5]) returns True deep_contains(3, 11, [3,5]]) returns True deep_contains (3, 1, [[3,4],5),6]) returns True deep_contains (2, (1,3,5]) returns False This function...

  • Define a Python function named getResponse() that takes a string as its only argument and returns...

    Define a Python function named getResponse() that takes a string as its only argument and returns a new string. If the argument ends with a question mark and has an even number of characters, the function should return the string "Yes". If the argument ends with a question mark and contains an odd number of characters, the function should return the string "No". If the argument ends with an exclamation point, the function should return the string "Wow". Otherwise, the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT