Question

thing WhatAmI(thing) 23 “integer” “23” “string with digits” “yabble” “string with letters” “yib4bie” “unidentified object” 23.0...

thing

WhatAmI(thing)

23

“integer”

“23”

“string with digits”

“yabble”

“string with letters”

“yib4bie”

“unidentified object”

23.0

“unidentified object”

“23.0”

“unidentified object”

Homework Answers

Answer #1

def whatAmI(thing):
    if type(thing) == int:
        return "Integer"
    elif type(thing) == str:
        digits = 0
        letters = 0
        for ch in thing:
            if ch.isdigit():
                digits += 1
            elif ch.isalpha():
                letters += 1
        if digits == len(thing):
            return "String with digits"
        if letters == len(thing):
            return "String with letters"
    return "unidentified object"


print(whatAmI(23))
print(whatAmI("23"))
print(whatAmI("yabble"))
print(whatAmI("yib4bie"))
print(whatAmI(23.0))
print(whatAmI("23.0"))

Know the answer?
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
Similar Questions
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and...
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and returns a string as output. The cencrypt() function you write in lab today needs to work on strings that contain upper-case letters, lower-case letters, or both. The output string should be all upper-case letters. (The Romans of Caesar's time used only what today we call upper-case letters.) So a call to cencrypt("Caesar", 1) should return (return not print) the string “DBFTBS” and a call...
Create a MIPS program that takes an ASCII string of hexadecimal digits inputted by the user...
Create a MIPS program that takes an ASCII string of hexadecimal digits inputted by the user and converts it into an integer.
2. License plates in a given state must consist of three letters followed by four digits....
2. License plates in a given state must consist of three letters followed by four digits. The state's DMV has determined that there are eighteen three-letter words that cannot appear on license plates, and there are five four-digit numbers that cannot appear. How many license plates are banned? Your answer may be given as an integer, or as a formula. Either is acceptable.
A meterstick of uniform density is hung from a string tied at the 23-cm mark. A...
A meterstick of uniform density is hung from a string tied at the 23-cm mark. A 0.40-kg object is hung from the zero end of the meterstick, and the meterstick is balanced horizontally. What is the mass of the meterstick? in kg
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as...
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as an input. The first task is to compute the frequency of each character appearing in the string. In the output, the characters have to be arranged in the same order as they appear in the input string. Then characters have to be rearranged, such that all the characters having a specific frequency, say xx, come together. Let the frequency of a character, lying in...
1. Complete a class Clock that represents time on a 24-hour clock, such as 00:00, 15:30,...
1. Complete a class Clock that represents time on a 24-hour clock, such as 00:00, 15:30, or 23:59 ○ Time is measured in hours (00 – 23) and minutes (00 – 59) ○ Times are ordered from 00:00 (earliest) to 23:59 (latest) Complete the first constructor of the class Clock ● It takes two arguments: h and m and creates a new clock object whose initial time is h hours and m minutes ● Test cases: Clock clock1 = new...