Skip to main content
added 77 characters in body
Source Link
Chris
  • 6.1k
  • 1
  • 7
  • 41

NewsConcerning is styled in the way PEP 8PEP 8 would tell us to style a class name. ItAs function it should be in snake case: news_concerning.

NewsConcerning is styled in the way PEP 8 would tell us to style a class name. It should be in snake case: news_concerning.

NewsConcerning is styled in the way PEP 8 would tell us to style a class name. As function it should be in snake case: news_concerning.

added 387 characters in body
Source Link
Chris
  • 6.1k
  • 1
  • 7
  • 41

Naming

NewsConcerning is styled in the way PEP 8 would tell us to style a class name. It should be in snake case: news_concerning.

String replacements

You can either convert the input immediately to lowercase, or let the NewsConcerning function do it.

Exception handling

Your try is miles from your actual exception handlers. The code in your try block should be as absolutely minimal as possible.

Boolean tests and false-y values

In a couple of places you do boolean tests on the length of lists or on whether strings are empty. You should be aware that empty strings are false in Python, as are empty lists.

String replacements

Naming

NewsConcerning is styled in the way PEP 8 would tell us to style a class name. It should be in snake case: news_concerning.

String replacements

You can either convert the input immediately to lowercase, or let the NewsConcerning function do it.

Exception handling

Your try is miles from your actual exception handlers. The code in your try block should be as absolutely minimal as possible.

Boolean tests and false-y values

In a couple of places you do boolean tests on the length of lists or on whether strings are empty. You should be aware that empty strings are false in Python, as are empty lists.

added 532 characters in body
Source Link
Chris
  • 6.1k
  • 1
  • 7
  • 41

This also removes the possibility for one call to str.replace to change the string so that a subsequent call will be triggered that otherwise wouldn't.

if __name__ == "__main__":
    i = input("Enter what you would ask of the voice assistant (eg:news concerning bitcoin): ")
    print(NewsConcerning(i))

Case sensitivity

As it stands, your program doesn't work very well if the user inputs mixed-case words. The fix is easy: convert the input to lowercase.

if __name__ == "__main__":
    i = input("Enter what you would ask of the voice assistant (eg:news concerning bitcoin): ")
    print(NewsConcerning(lower(i)))
if __name__ == "__main__":
    i = input("Enter what you would ask of the voice assistant (eg:news concerning bitcoin): ")
    print(NewsConcerning(i))

This also removes the possibility for one call to str.replace to change the string so that a subsequent call will be triggered that otherwise wouldn't.

if __name__ == "__main__":
    i = input("Enter what you would ask of the voice assistant (eg:news concerning bitcoin): ")
    print(NewsConcerning(i))

Case sensitivity

As it stands, your program doesn't work very well if the user inputs mixed-case words. The fix is easy: convert the input to lowercase.

if __name__ == "__main__":
    i = input("Enter what you would ask of the voice assistant (eg:news concerning bitcoin): ")
    print(NewsConcerning(lower(i)))
added 532 characters in body
Source Link
Chris
  • 6.1k
  • 1
  • 7
  • 41
Loading
added 532 characters in body
Source Link
Chris
  • 6.1k
  • 1
  • 7
  • 41
Loading
Source Link
Chris
  • 6.1k
  • 1
  • 7
  • 41
Loading