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
#1
So I need to return the value '-1' when s = any non-digits (other than spaces).
my code so far looks like :
def parseVote(s=None):
    if not s:
         print('0')  
    elif s >= 0:
         print(s)
    else :
        print(-1)
But its the middle 'elif' that needs changing to include letters. 
Thankyou!!

Actually might as well post whole question to make it easier.
def parseVote(s):
parseVote(s) returns the vote from s. Return 0 for an empty vote, and -1 if there are any non-digits (other than spaces). For example,
parseVote("") = parseVote(" ") = 0,
parseVote("-3") = parseVote("no") = parseVote("1 5") = -1,
parseVote("15") = parseVote(" 15 ") = 15.
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 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,278 Jan-13-2023, 09:48 PM
Last Post: Gribouillis
  How to do bar graph with positive and negative values different colors? Mark17 1 5,233 Jun-10-2022, 07:38 PM
Last Post: Mark17
  Regex: positive lookbehind Secret 2 2,030 Sep-21-2020, 12:59 AM
Last Post: snippsat
  Positive to negative bernardoB 6 4,427 Mar-13-2019, 07:39 PM
Last Post: bernardoB
  negative to positive slices Skaperen 3 3,669 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