954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

While Loop

In my programming class, we need to write a program where the user is prompted for a value. Once that value is provided, the program is supposed to multiply its digits. For example: if the user typed 1234, it would multiply 1*2*3*4 and give the answer. I'm not sure how to multiply the digits and my teacher mentioned using a while loop.

demeryjo
Newbie Poster
3 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

This problem is really simple:
1. You can loop python strings like anyway other container.
2. You can convert a digit string ("1") to an integer (1) using int()

I'm not even going to tell you how to do the rest. Go ahead and prove that you aren't lazy.

scru
Posting Virtuoso
1,629 posts since Feb 2007
Reputation Points: 975
Solved Threads: 140
 
I'm not sure how to multiply the digits


Here's multiplication in Python

>>> 1 * 2 * 3 * 4
24
>>>


I suggest you peruse the Python documentation to learn yourself something. I suggest the First Steps Towards Programming section

jlm699
Veteran Poster
1,112 posts since Jul 2008
Reputation Points: 355
Solved Threads: 292
 
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You