On 09/07/2017 10:20 AM, edmundo pierre via Tutor wrote: > > I am trying to write a code that asks an User to Enter a decimal number, the > my program should separate the number in two parts like this: > 1 cae:Enter a number: 12.9Decimal part: 12whole part : 9 > 2 case:Enter: 10Decimal par:Whole part: 10 > That is my code: > A = input("Enter a number") > C = [ ] for i in str(A) : > C.append(i) if i ==".# period ": break aa= "".join(c) > print(aa, end =" ") > if i == int(A): print(" It is the whole part") > I can not display the whole part when I enter float number. Plus when I enter > an integer, it takes that enteger as a decimal number. Any help?
Depending on what you have already learned, these hints may be helpful. 1. type() will let you experiment with what Python thinks you got. So as to the second question, A = input("Enter a number") print(type(A)) if it is not what you expected, how can you get it to something you can work with. Hint: you're already doing that once in your code. 2. strings are easy to split into pieces. See the split() method. This simple tutorial might give you an idea: http://www.pythonforbeginners.com/dictionary/python-split _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor