[Tutor] Fwd: Re: Adding consecutive numbers

Alan Gauld alan.gauld at btinternet.com
Wed May 6 13:51:53 CEST 2015


Please use ReplyAll to include the list members.


-------- Forwarded Message --------
Subject: 	Re: [Tutor] Adding consecutive numbers
Date: 	Wed, 6 May 2015 21:13:15 +1000
From: 	Whom Isac <wombingsac at gmail.com>
To: 	Alan Gauld <alan.gauld at btinternet.com>



Thanks for the reply. I am sorry that I did not notice the mail. I am 
actually using the latest version of python (3.5) in windows 7 operating 
system. I have already made certain changes in the code. I understood my 
mistake. The correction's are not finished yet,though. You can have a 
look at it, because, I donot know what I have written is already in 
right syntax or not.

Here are my code:
##Goal: Building a math program.
## two nums will be asked by the user
## they will be added
## condition: num >=o:
## num will continue to be added into a list untill the second number
## For your information, a consequitive sequence of num : num-->1 
num1--> num+1...+n

if __name__=='__main__':
     interact()

def interact():
     print('''Welcome to My new Math program!!
     With this program, you can find the sum of any consequitive 
numbers.''')
     print('So Just add your numbers in following spaces')
     ## If anybody complaining about this function. I will have to say, 
that the coding is incomplete so
     ## I will first define all my function then def interact() when I 
am finishing.


def getting_numbers(first_num, second_num):
     x = [] #This is a empty list to store data
     y = [] #This is a empty list to store data
     """Getting the user values:"""
     first_num =int(input('Please enter your first number: '))
     x.append(first_num) # adding the input in x#
     second_num =int(input('Please enter your second number: '))
     y.append(second_num) # adding the input in x#
     z =(x,y) # This is a touple containing both x and y value.
     return z

def adding_all(x):
     total = 0
     for num in x:
         total +=num
     return total
def remove_letter(x):
     if x != len(x):
         print('You did not enter a number')
     elif x != adding_all(x):
         print("Please, donot include letters")
     else:
         return x
         ## I think using a while True function to iterate all item in x 
would be better.



def adding_number(x,y):
     start = x[0]
     end = y[0]
     new_x = 0
     new_x_1 = 0
     while x[0]<=y[0] or x[0]<= 0:
         if x[0]==0:
             new_x+=1
             return new_x
         elif x[0]>0 or x[0]<y[0]:
             new_x_1+=x[0]
             return new_x_1
         else:
             pass
             print("You have not input a digit in order, check your 
digits\n")
             print("I donot know what you mean?")

On Mon, Apr 27, 2015 at 10:16 PM, Alan Gauld <alan.gauld at btinternet.com 
<mailto:alan.gauld at btinternet.com>> wrote:

    On 27/04/15 11:37, Whom Isac wrote:

        num1 entry =1 & num2 entry = 100 , the program should be adding
        number from
        1 to 100 together(which should equal to 5050).


        I have uploaded my code file below.


    Infortunately we can't see it.
    Since it is presumably quite short please just send it
    in the body of your email.

    Also include the full error text that you refer to,

    Also tell us the Python version and OS you are using.

    -- 
    Alan G
    Author of the Learn to Program web site
    http://www.alan-g.me.uk/
    http://www.amazon.com/author/alan_gauld
    Follow my photo-blog on Flickr at:
    http://www.flickr.com/photos/alangauldphotos


    _______________________________________________
    Tutor maillist  - Tutor at python.org <mailto:Tutor at python.org>
    To unsubscribe or change subscription options:
    https://mail.python.org/mailman/listinfo/tutor






More information about the Tutor mailing list