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