Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BBCode tags
#1
So I am trying to create a function for odd integers. I would like to have the user input any number and then have the program test if it is evenly divisible by 2. If so, I would like it to return False and if it is not true I would like to return True. Here is what I have so far:

print("PRACTICE 2.")

number = input("Enter a number, please: ")

def is_odd(number):
if number % 2 == 0:
return False
else:
return True
is_odd(number)

Output:
Enter a number, please: 5 (entered by me to test)
Traceback (most recent call last):
File "python", line 13, in <module>
File "python", line 9, in is_odd
TypeError: not all arguments converted during string formatting
Reply
#2
Use python tags. You have been asked to do this repeatedly.

You need to convert number to an integer with int() before applying the % operator.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Jan-07-2019, 05:50 PM)ichabod801 Wrote: Use python tags. You have been asked to do this repeatedly. You need to convert number to an integer with int() before applying the % operator.

I never see the option to add any tags so apologies, repeatedly. So like:

number = (int(input("Enter a number, please: ")) ?
Reply
#4
(Jan-07-2019, 05:55 PM)NLittle17 Wrote: I never see the option to add any tags so apologies
read the help docs about BBCode
https://python-forum.io/misc.php?action=help&hid=25

You need to learn to use code tags otherwise you will be restricted from posting.

In addition to that, please be more specific in title descriptions. Your two questions were not the same, but had the same title. I almost merged them together until i realized they were different questions. I fixed your two thread titles to identify the main question of each thread.

EDIT: I just realized you made a 3rd thread, however used proper BBCode. In that case, ill just move this to Board for BBcode instructions as the other thread is a duplicate.
Recommended Tutorials:
Reply
#5
Nlittle17 - when you make a post, do you see those little icons above the text box, mainly the blue and yellow python icon? Click that, stick code between the python tags.
Reply
#6
and errors between icon circle with X in middle.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with BBCode pyJim 2 3,844 Aug-22-2017, 10:05 PM
Last Post: snippsat
  Do not know how to add "Code Tags" or "Error Tags" to my submissions mattkrebs 2 3,675 Mar-21-2017, 04:15 PM
Last Post: metulburr
  BBcode pointer position metulburr 0 2,914 Dec-15-2016, 01:35 PM
Last Post: metulburr
  bbcode fail [list=0] Skaperen 2 3,804 Nov-12-2016, 01:49 PM
Last Post: metulburr
  BBCODE disappears on full edit Larz60+ 3 4,766 Nov-08-2016, 01:26 AM
Last Post: Larz60+
  BBcode help spoiler in editor metulburr 1 3,846 Oct-20-2016, 05:27 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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