Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 confusion on looping :(
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
burmantanya




PostPosted: Sun Oct 12, 2008 8:59 am   Post subject: confusion on looping :(

Hello Everyone on compsci.ca =)

i am working on this program..a lil bit confused..please let me know where i am going wrong
my task is to create a program which does the following things

- it has to get a number from the user
if the number is less than 10, it just prints 10
but if the number is greater than 10 less than 100, it keeps on dividing by 10 until lowest remainder is found and then converts the remainder into an aplhabet
and if the number is greater than 100 but less than 1000, it divides by 100 until lowest remainder is achieved and then divide by 10, and convert the remainder into alphabet but all the quotients are the answers.

for example:
666. divide 666 by 100. you get 6. left with 66. divide 66 by 10. you get 6 and are left with 6. that means the answer is 66F

here is a sample tryout i have till now..

def conv_num_alpha():

input_number = input(x)

if input_number < 10:
print input_number

elif input_number 10<x<100:
step1 = input_number/10
print step1 [ OVER HERE, I NEED THE QUOTIENT TO REMAIN SAME, BUT THE REMAINDER TO CHANGE INTO ALPHABETS]

elif input_number > 100:
step2 = input_number/100 (until its possible)
[if the remainder is not divisible by 100, switch to dividing by 10 until its possible and displays the answer as shown in the example]

what else do i need to add/subtract. Do i make a list for the alphabets???
Sponsor
Sponsor
Sponsor
sponsor
Zeroth




PostPosted: Sun Oct 12, 2008 12:12 pm   Post subject: Re: confusion on looping :(

First, please, please, use code tags. Very very easy. Just use [] with code inside the square brackets then to finish it off, [] with /code inside the square brackets.

Next,

I'm not solving your problem... but you can turn letters into their ascii codes, and vice versa. (Take a look at this table: http://www.asciitable.com/)

To turn letters into ascii code and back:
code:

print ord('a')
print ord('A')
print chr(65)
print chr(65+0)
print chr(65+6-1)


That should help.
burmantanya




PostPosted: Sun Oct 12, 2008 1:39 pm   Post subject: RE:confusion on looping :(

oOo..interestingg
what does ord and chr stand for?

man..i seriously need to thank you million times..u r very good at programming..i really appreciate that you take out time to read and help people..
burmantanya




PostPosted: Sun Oct 12, 2008 1:44 pm   Post subject: RE:confusion on looping :(

i was wondering that is it possible for us to convert a string into an interger and then convert interger back into a string???
burmantanya




PostPosted: Sun Oct 12, 2008 2:03 pm   Post subject: RE:confusion on looping :(

oh btw..the link u send me..thats what exactly i have to do..convert the base 10 to hexa
but can't use inbuilt functions Sad
btiffin




PostPosted: Sat Oct 18, 2008 11:43 am   Post subject: Re: RE:confusion on looping :(

burmantanya @ Sun Oct 12, 2008 1:39 pm wrote:
oOo..interestingg
what does ord and chr stand for?


I can't really speak to where chr came from (made up short form of Character if I had to guess), but ord is short for Ordinal, a number (or word) denoting order or succession. Given that; chr is the "opposite" of ord. It gives the character element that is the given Ordinal of the set. We mostly live in an ASCII world, but EBCDIC is another machine alphabet and Unicode is putting paid to most of these "easy" routines. A "character" is quickly losing its currently common one byte representation.

Along with Ordinal, there is Cardinal. Best by example. First, Second and Third are "Ordinal numbers". One, Two and Three are "Cardinal numbers".

Cheers
Zeroth




PostPosted: Sun Oct 19, 2008 9:38 am   Post subject: Re: confusion on looping :(

Then you need to create a function+a data structure for taking a single character string, and returning its numerical value.

Think of it this way: You create a data structure, say using one of Python's built-in data types, that has say, takes a single character string as some sort of key or index, and returns the numerical value... If you can't figure that out, use a very long if, else if, else statement.
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: