473,836 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting the sum of digits in a number

16 New Member
i made it like this:
Expand|Select|Wrap|Line Numbers
  1. def tvarsumman(n):
  2.     if n<10:
  3.         print n
  4.     else:
  5.         tvarsumman((n/10) + n%10)
but when it comes to 99 it does this

99--> 9+9=18-->1+8=9

thats wrong according to my professor.

can u help fix my function?

and all the ones u have made so far have been perfect! u are really helping me. thank u sir! :P
Oct 25 '07
11 15601
DDCane
16 New Member
Nope, Youre entirely correct. I'm from Sweden.
I klicked report insted of reply :/ meh.
Hey guys! Actually I'm American but I live in Sweden at the moment. Where in Sweden are from?
Oct 27 '07 #11
Smygis
126 New Member
Hey guys! Actually I'm American but I live in Sweden at the moment. Where in Sweden are from?
Up in the north. Live somewhere in the area around Umeå now.
Oct 27 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2322
by: Spidah | last post by:
Is there an easier way to get the number of items in a database table than selecting all the records in it and then running mysql_num_rows on the result? Hamilton www.laughland.biz
5
1617
by: ssmith579 | last post by:
I'm trying to extract single digit number from a string. t = '06897' I want to get the 7, 9,8 & 6 seperated out to use but can't find a way to split out the single characters. Thanks
4
10254
by: Shahar | last post by:
Hi I need to get a field name 'ID'(that is an auto-number field) right after I add a new row to table, it's work like that: myCommand.ExecuteNonQuery(); myCommand.CommandText = "SELECT @@Identity"; // the auto-number fiels int iId = (int)myCommand.ExecuteScalar();
0
1388
by: John Shum | last post by:
I prepare a UserControl that act as a lookup control, once the code is enter in the TextBox, the description will appear in another TextBox outside the UserControl of the same row in a DataGrid via javascript. I attempt to get the client ID of the TextBox (with provided ID of that TextBox as "ext_desc") by the following code inside the Page_Load() event of the UserControl (named Color_Control): for(int i = 0; i < DataGrid1.Items.Count;...
4
2313
by: UJ | last post by:
Is there a way to get the number of items that are in an enum? I'm trying to find out how many items there are so that I can hit every one of them to test. TIA - Jeff.
1
941
by: amiga500 | last post by:
Hello, I have a data grid which can contain as many items as possible in one of the columns I have Qty. What I want to do is when I run the forum I want to get the number of items available in the datagrid..for example as follows: ItemNumber ItemName Qty 1111111 Apple 2
0
1280
by: FORGET | last post by:
Can anybody show me how to get the serial number of a pocketpc using VC++? I can get the PDA name with RegQueryValueEx, but I have no idea what to send for the serial number. Thanks
0
1079
by: StanislavPetrov | last post by:
How to get the number of the current line in a RichTexBox?I mean the line under the mouse cursor.
6
5031
by: Gangreen | last post by:
Visual Basic.net : is there a way of getting the number of threads?
6
2285
by: jeddiki | last post by:
I am writing a little script that will improve authors writing skills by finding repeated phrases in the text. The text of a chapter will average about 10,000 words, however, I could reduce the size of the files if it is better to do so. So the idea is to search through a string and find repeats of any 3 or 4 word group. So if the author has repeated the phrase "then I went" 6 times in the text, then this would be found and...
0
9820
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9670
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9374
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4016
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.