Counting loop

This is the place for queries that don't fit in any of the other categories.

Counting loop

Postby vadimak » Sat May 04, 2013 2:23 am

How can i make a Coaunter in loop for example program will ask me for number again and agin antil i input "Done" and then its printing me ount the sum of numbers.

i am sorry for this stupid Qusion but i am only started to learn python
vadimak
 
Posts: 15
Joined: Wed May 01, 2013 1:07 pm

Re: Counting loop

Postby micseydel » Sat May 04, 2013 2:36 am

What attempt have you made? Could you show an example input/output session?
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1369
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Counting loop

Postby vadimak » Sat May 04, 2013 2:39 am

input output
2
3
5
1
9
2
Done_________22
vadimak
 
Posts: 15
Joined: Wed May 01, 2013 1:07 pm

Re: Counting loop

Postby micseydel » Sat May 04, 2013 2:43 am

micseydel wrote:What attempt have you made?
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1369
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Counting loop

Postby vadimak » Sat May 04, 2013 2:47 am

Code: Select all
znum==1
if inum==1:
    inum=input("please in put a number")
    tnum=inum+inum

if znum==done:
    print "",tnum



:? :? :?
vadimak
 
Posts: 15
Joined: Wed May 01, 2013 1:07 pm

Re: Counting loop

Postby hansn » Sat May 04, 2013 8:02 am

I suggest you go read a python book for beginners.

Code: Select all
sum = 0
ans = ''
while ans.lower() != 'done':
    if ans.isdigit():
        sum += int(ans)
    ans = raw_input('Please enter a number ')
print 'Done___________%d' % sum
hansn
 
Posts: 87
Joined: Thu Feb 21, 2013 8:46 pm

Re: Counting loop

Postby metulburr » Sat May 04, 2013 1:20 pm

Code: Select all
lister = []

while True:
   var = input('Input number or "done" to exit loop')
   if var == 'Done':
      break
   else:
      try:
         intvar = int(var)
      except ValueError:
         continue
      lister.append(intvar)

total = sum(lister)
print(total)
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Counting loop

Postby vadimak » Sat May 04, 2013 2:45 pm

Thank you ';DDDDDDD
vadimak
 
Posts: 15
Joined: Wed May 01, 2013 1:07 pm

Re: Counting loop

Postby Kebap » Mon May 06, 2013 8:56 am

Quoted for Reference
vadimak wrote:How can i make a Coaunter in loop for example program will ask me for number again and agin antil i input "Done" and then its printing me ount the sum of numbers.

i am sorry for this stupid Qusion but i am only started to learn python

vadimak wrote:input output
2
3
5
1
9
2
Done_________22

vadimak wrote:
Code: Select all
znum==1
if inum==1:
    inum=input("please in put a number")
    tnum=inum+inum

if znum==done:
    print "",tnum

:? :? :?

vadimak wrote:Thank you ';DDDDDDD

Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Coding Help

Who is online

Users browsing this forum: buran, Google [Bot] and 5 guests

cron