Discussion:
[Tutor] Fwd: Re: Adding consecutive numbers
Alan Gauld
2015-05-06 11:51:53 UTC
Permalink
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 <***@gmail.com>
To: Alan Gauld <***@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 <***@btinternet.com
<mailto:***@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 - ***@python.org <mailto:***@python.org>
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor




_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Mark Lawrence
2015-05-06 12:57:34 UTC
Permalink
Post by Alan Gauld
-------- Forwarded Message --------
Subject: Re: [Tutor] Adding consecutive numbers
Date: Wed, 6 May 2015 21:13:15 +1000
I am actually using the latest version of python (3.5) in windows 7 operating
system.
Why are you using a version of Python that hasn't had a beta release
yet? Or have you simply mistyped the version number?
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Dave Angel
2015-05-06 14:01:22 UTC
Permalink
Post by Alan Gauld
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
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.
##Goal: Building a math program.
## two nums will be asked by the user
## they will be added
## 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
interact()
You get an error right there, since interact() isn't defined yet. Move
the above two lines to the end of the file.
Post by Alan Gauld
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.
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
Why are you so enamored with lists? You're returning a tuple containing
two lists each of which has exactly one value? Why not just return a
tuple of first_num and second_num ?
Post by Alan Gauld
total = 0
total +=num
return total
Good function.
What do you think that statement does? It can't possibly do anything
useful since the right side assumes that x is a collection or
equivalent, and the left side assumes that x is a number.
Post by Alan Gauld
print('You did not enter a number')
print("Please, donot include letters")
return x
## I think using a while True function to iterate all item in x
would be better.
Considering that after you call each input() function, you immediately
call int(), I'd figure that checking for "you did not enter a number" is
superfluous.
Post by Alan Gauld
start = x[0]
end = y[0]
new_x = 0
new_x_1 = 0
new_x+=1
return new_x
new_x_1+=x[0]
return new_x_1
pass
print("You have not input a digit in order, check your
digits\n")
print("I donot know what you mean?")
I can't make any sense out of anything in this function.

I think you need to write one function and include descriptive comments
in it, and write code that tests it against those comments. Then when
you have one function that successfully runs, write a second one.
--
DaveA
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-05-06 14:20:45 UTC
Permalink
Post by Dave Angel
Post by Alan Gauld
total = 0
total +=num
return total
Good function.
Except for the fact that the built-in sum() function
does the same thing with a lot less typing...
--
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 - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Whom Isac
2015-05-06 12:13:31 UTC
Permalink
Thanks, Steven. I think you are right about those mistake. But you could
tell that the code was incomplete so the interact() was not defined. I have
updated some parts (basically writing from the scratch). I am busy with a
new project and learning how to create GUI app in python, although there
are not enough source to aid me. I will just post the code here for now:
Thanks, Steven. I think you are right about those mistake. But you could
tell that the code was incomplete so the interact() was not defined. I have
updated some parts (basically writing from the scratch). I am busy with a
new project and learning how to create GUI app in python, although there
are not enough source to aid me. I will just post the code here for now:


##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\n")
print("I donot know what you mean?")
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Continue reading on narkive:
Loading...