0

I'm trying to write a function that returns True if integer n is positive and odd (otherwise False). Then use this function to repeatedly ask a user to enter a positive and odd integer until a (positive and odd) integer has been provided up to five times and return the value once it fulfils the positive/odd criteria.

I can get it to return if it's true or false but I'm getting stuck on the rest.

Here's what I've tried:

x = int(input("enter a number: "))
values = [5]
def isOdd(x):

    if x % 2 != 0 and x>0:

           return True
        print("yup")
     else:
           return False
        print("no")


'''while count = <5 and x % 2 != 0 and x>0: #this is a different approach I tried
    count = sum x+1
    print ("no")
    x = int(input("enter a number: "))'''

    
for i in range(x):
    values.append(int(input('Please enter a value')))

What am I missing here? I'm new to programming and having a little bit of trouble figuring out functions and append.

Changed code to:

x = int(input("enter a number: "))
def isOdd(x):

    if x % 2 != 0 and x>0:

           return True
        print("yup")
     else:
           return False
        print("no")


while count <=5 and not isOdd(x):
    count = sum x+1
    print ("no")
    x = int(input("enter a number: "))

Getting this error now:

line 12
    print("yup")
               ^
IndentationError: unindent does not match any outer indentation level
AMC
  • 2,642
  • 7
  • 13
  • 35
Lizziekil
  • 1
  • 2
  • *until a proper (positive and odd) integer has been provided* What is a proper number? – Red Sep 23 '20 at 21:12
  • Oh I'll remove that, never mind the word proper. – Lizziekil Sep 23 '20 at 21:21
  • Does this answer your question? [IndentationError: unindent does not match any outer indentation level](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) – AMC Sep 23 '20 at 22:02
  • Your indentation problem is an unrelated issue. You have to post this as a separate SO question ... except that it's a simply typo: fix your indentation. If you're confused, look up Python indentation requirements. – Prune Sep 23 '20 at 22:09

1 Answers1

0

You're very close. You just need to call your function with the input value, and the use the result:

# Stay in this loop until 5 wrong guesses, or one right guess.
while count <=5 and not isOdd(x):
Prune
  • 76,765
  • 14
  • 60
  • 81
  • Thanks for your answer. I changed the code to include your answer. it's giving me the error: ` print("yup") ^ IndentationError: unindent does not match any outer indentation level ` When my code is: ` x = int(input("enter a number: ")) def isOdd(x): if x % 2 != 0 and x>0: return True print("yup") else: return False print("no") while count <=5 and not isOdd(x): count = sum x+1 print ("no") x = int(input("enter a number: ")) ` – Lizziekil Sep 23 '20 at 21:20
  • (1) A follow-up question goes into a new posting. (2) Your original posted code contains this error; it's not due to what I suggested. (3) As you can see, a comment is a nearly useless way to post code. – Prune Sep 23 '20 at 21:22
  • Sorry, I edited the question and added the current code and error. I'm new to Stackoverflow and appreciate your help :) – Lizziekil Sep 23 '20 at 21:27