Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to Python
#1
Hello all.

New to forums.

1st, if there are any sticky posts that contain links to helpful resources, I'd love someone to post a link.

I'm working my way through code academy's python course and I'm stuck and don't want the answer given to me directly on their forums. This is the explanation from the code academy workspace:

Explanation:
An integer is just a number without a decimal part (for instance, -17, 0, and 42 are all integers, but 98.6 is not).
For the purpose of this lesson, we'll also say that a number with a decimal part that is all 0s is also an integer, such as 7.0.
This means that, for this lesson, you can't just test the input to see if it's of type int.
If the difference between a number and that same number rounded is greater than zero, what does that say about that particular number?

Problem:
Define a function is_int that takes a number x as an input.
Have it return True if the number is an integer (as defined above) and False otherwise.


And here is my code so far:
def is_int(x):
  NEED HELP HERE
    return True
  else:
    return False
I'm unsure what the explanation is looking for here. I understand that I should be looking to see if the number is 7.6 or 7.1 vs just 7.0 or 7, but I'm unsure which python capability I should be writing my if statement with.

Can anyone point me in the right direction without directly giving me the answer?

Thanks and looking forward to getting to know people.
Reply
#2
you need to write a function that will return True if the argument it gets (x) is integer and False otherwise. In Explanation section it explains what integer is.
Reply
#3
This part says I can't just test for type integer though?

This means that, for this lesson, you can't just test the input to see if it's of type int.

if I could use int I could do:
def is_int(x):
  if x == type<int>:
    return True
  else:
    return False
Reply
#4
You could try and create variables from the passed argument(that is x in your function) and then do something like:

x_raw #assign x directly to this
x_rounded #find a python function to round number
x_difference #check if x_raw and x_rounder are equal

if x_difference != 0:
#think about what you should return here
else:
#same for this 
Reply
#5
(Feb-22-2018, 08:37 PM)Buffy Wrote: If the difference between a number and that same number rounded is greater than zero, what does that say about that particular number?
The key to solve it is the answer of this question
Reply


Forum Jump:

User Panel Messages

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