Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Functions in Python
#1
I am trying to write a script that takes in a number and returns True of it is odd and False if it is even. Here’s what I have so far. I want to use the return method but nothing is coming out after I run it.
def is_odd(number):
  number = int(input("Enter a number: "))
  if number % 2 == 0:
    return False
  else:
    return True
Reply
#2
Please use python and output tags when posting code and results. I put them in for you this time. Here are instructions for doing it yourself next time. You've been asked to do this before, and if you don't start doing it yourself, you will start getting warnings.

The function is kind of screwy, but it is returning a value. The screwy part is that you are requiring a number be passed as a parameter, but then you are asking for it with input and overriding the parameter.

Note that you need to call the function for it to do anything. As in is_odd(3).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

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