How do you check if your function returns nothing?

PurpleHyacinth

I'm trying to answer a question from a challenge.

Question: Some numbers have personality, while other numbers are just dull. Let's write a program that asks for a list of numbers and describes the interesting ones using the personality traits below, while counting up all the dull ones without traits.

Your program should ask for a list of space-separated numbers. For any number with at least one trait, it should print a full description of its personality. Then it should print how many dull numbers were counted.

Here's my solution for it:

arrogant_numbers = [3, 6, 7, 23, 25, 35, 39, 66, 68, 112, 119, 254, 259, 732, 737, 4565, 4663, 13330, 13730, 29880, 29998, 79670, 80015, 230054, 239068, 1534301, 1607352, 2060587, 21700891, 99167753, 99873125]

def find_personality(number):
  traits = ''
  # Find the traits of the number
  if number % 2 != 0:
    traits = traits + 'odd '
  # Check for other traits after this
  if number >10000:
    traits = traits + 'excessive '
  if '3' in str(number): 
    traits = traits + 'irksome '
  if number in arrogant_numbers:
    traits = traits + 'arrogant '
 
  return traits 

# Write the rest of your program after this
dullcounter = 0
numbers = input('Enter numbers: ')
number_list = numbers.split()
for word in number_list: 
  trts = find_personality(int(word))
  print(f"{word} is an {trts}number.") 
  if '' in trts:
    dullcounter = dullcounter + 1
print(f'Dull numbers: {dullcounter}')

I'm having problems with counting the dull numbers (the ones that have no traits) it counts all the numbers given instead of the ones that have no traits.

Here's how the final solution should look like: desired output

Here's how my output looks like: my output

Prophet

Your output string trts will always contain ''.
Instead of this you should validate if trts is an empty string.
So, instead of

if '' in trts:
    dullcounter = dullcounter + 1

you should use this or similar:

if not trts:
    dullcounter = dullcounter + 1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do you get to the value inside of a python function that returns nothing for unit testing?

In Julia, How do you check, list, update your packages?

How to create function that returns nothing

How Do you access function props in your class component?

How do you incorporate Java's main function into your design?

How do you use the require function on your website?

How do you annotate a flowtype of a function that returns a slice of state?

How do you print a function that returns a request in Python?

`hot_to_r()` function from `rhandsontable` package not working inside a "normal" .R script - how do you check the aspect of your datas inside shiny?

How do you check if your signing identity is installed on another Mac? (Error: Your Account already has a valid iOS Distribution Certificate)

How do you check the difference between an ECMAScript 6 class and function?

How do you check the difference between an ECMAScript 6 class and function?

How do you check in which module a function is defined? Python

How do you scale your ActiveMQ vertically?

How do you organize your file downloads?

How do you manage your gists on GitHub?

How do you debug your Nest queries?

How do you change your username in Manjaro?

How do you get your location in javascript?

How do you reset your password for thunderbird?

How do you block a port on your loopback?

How do you decide whether your function should use a pointer as is receiver?

python function returns nothing

Return function returns nothing

How to check if you actually got an result from your aggregate

How do you write a function pointer that returns a function pointer without using typedefs?

How do you declare a function in Scala that returns itself (or another function with the same signature)?

Check if a command returns nothing in Makefile

How do you access the BIOS if your machine boots too fast for you to enter it, but your OS is broken?

TOP Ranking

HotTag

Archive