Python Forum
How to find any non positive integer
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to find any non positive integer
#2
There are several things wrong with your code:

1. You're printing, not returning a value.
2. The values you pass are strings, so the condition on the elif doesn't make sense.

If you need to try and parse a string as an integer, use the int() function. It raises an exception of type ValueError when its argument can't be converted, so you'll need to use a try/except to handle that.
Reply


Messages In This Thread
How to find any non positive integer - by noob - Apr-27-2017, 11:15 AM
RE: How to find any non positive integer - by ndc85430 - Apr-27-2017, 12:15 PM
RE: How to find any non positive integer - by noob - Apr-27-2017, 03:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Positive integral solutions for Linear Diophantine Equation august 4 1,310 Jan-13-2023, 09:48 PM
Last Post: Gribouillis
  How to do bar graph with positive and negative values different colors? Mark17 1 5,310 Jun-10-2022, 07:38 PM
Last Post: Mark17
  Regex: positive lookbehind Secret 2 2,046 Sep-21-2020, 12:59 AM
Last Post: snippsat
  Positive to negative bernardoB 6 4,477 Mar-13-2019, 07:39 PM
Last Post: bernardoB
  negative to positive slices Skaperen 3 3,693 Jan-29-2018, 05:47 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020