Rounding to the nearest 5
How can you make python round numbers to the nearest 5: Example: 3 => 0 8 => 10 23.2 => 20 36 => 35 51.5 => 50 Thanks! _ Twice the fun—Share photos while you chat with Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx-- http://mail.python.org/mailman/listinfo/python-list
Using while loop and if statement to tell if a binary has an odd or even number of 1's.
Using while loop and if statement, I'm trying to get Python to tell me whether there are even or odd number of 1's in a binary representation. For example, if I give Python a 0111, then I want it to say that the binary representation given has an odd number of 1's. If I give it 00010111, then it will tell me that there is an even number of 1's. I'd appreciate any suggestion. Thanks! _ So many new options, so little time. Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx-- http://mail.python.org/mailman/listinfo/python-list
RE: Using while loop and if statement to tell if a binary has an odd or even number of 1's.
By "binary representation", I mean a byte of 0s and 1s. Example: 0101 Also, I'm interested in only using while loop and if statement to accomplish this task. Thanks.> Date: Wed, 4 Feb 2009 17:18:25 -0800> Subject: Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.> From: c...@rebertia.com> To: todp...@hotmail.com> CC: python-list@python.org> > On Wed, Feb 4, 2009 at 5:02 PM, todp...@hotmail.com wrote:> > Using while loop and if statement, I'm trying to get Python to tell me> > whether there are even or odd number of 1's in a binary representation.> > For example, if I give Python a 0111, then I want it to say that the> > binary representation given has an odd number of 1's.> > If I give it 00010111, then it will tell me that there is an even number of> > 1's.> > I'd appreciate any suggestion.> > Please define "binary representation". Do you mean a sequence of> bytes, an integer, a string of 0s and 1s, or something else entirely?> > If it's a string of 0s and 1s, then:> is_even = zerosones.count('1') % 2 == 0> > For an integer:> is_even = bin(the_int)[2:].count('1') % 2 == 0> > For the others, I don't know offhand.> > Cheers,> Chris> > -- > Follow the path of the Iguana...> http://rebertia.com _ The new Windows Live Messenger. You don’t want to miss this. http://www.microsoft.com/windows/windowslive/messenger.aspx-- http://mail.python.org/mailman/listinfo/python-list
Feet and inches
I'm trying to get Python to say: Enter the height (in metres): and convert whatever value to feet and inches. I've done this part as you can see below, but how can I terminate the program when user inputs a height less than 1/2 inch? How can I also take into account all the cases that need an exception? metres = float(raw_input("Enter the height (in metres): "))total_inches = 39.37 * metresfeet = int(total_inches/12)inches = int(round(total_inches - feet*12))if feet>=1:print "It is " + str(feet) + " feet " + str(inches) + ' inches high.'if feet<1 and inches<0.5:print "Error." _ Windows Live Messenger. Multitasking at its finest. http://www.microsoft.com/windows/windowslive/messenger.aspx-- http://mail.python.org/mailman/listinfo/python-list
Converting numbers to words
I've been trying to figure this out for over 2 hours and I'm really frustrated right now.I first made Python to ask user to input height in meters. If user puts certain value in meter, then it converts it to feet and inches as follows: Enter the height (in metres): 1.6It is 5 feet, 3 inches high. What I want to do is to make it type only words. For example, instead of its saying, "It is 5 feet, 3 inches high," I want it to say, "it is five feet, three inches high."I'd appreciate any suggestions. _ Twice the fun—Share photos while you chat with Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx-- http://mail.python.org/mailman/listinfo/python-list
Putting asterisks around text
I'm trying to write a program that puts asterisks around the input text using while loop. I can do this without using while loop, but how can you do that using while loop?Example:Enter a string: Hello world***Hello world*** _ So many new options, so little time. Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx-- http://mail.python.org/mailman/listinfo/python-list
RE: Putting asterisks around text
From: todp...@hotmail.comto: python-l...@python.orgsubject: Putting asterisks around textDate: Mon, 9 Feb 2009 10:09:26 -0800 I'm trying to write a program that puts asterisks around the input text using while loop.I can do this without using while loop, but how can you do that using while loop?Example:Enter a string: Hello world***Hello world*** I'm not necessarily asking for an answer. A hint would be grateful as well. _ So many new options, so little time. Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx-- http://mail.python.org/mailman/listinfo/python-list