please help me with this little "number program"

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

please help me with this little "number program"

Postby djeasily » Sun Oct 27, 2013 12:23 pm

####Dear all

I just wrote this little programm below. It works fine so far.

However, I would like to do one more thing. When someone enters a number more than once, I would like the program to stop. so if somebody types raw input 5 and then raw input 5 again, the program should come to a halt. I just don't know how I can integrate this condition in my code. However, I know that it must be pretty easy as I can just compare the raw input with the data in the list that I defined (zahlenliste). I would be very grateful for some help.

best wishes

Marcel ####


Code: Select all
print 'Please enter a number (from 1 to 9):'

value = 1
counter = 0
zahlenliste = []


while value < 50:
   
   input=int(raw_input())
   
   if input <1 :
      print 'error'
      print 'Please enter a number (from 1 to 9):'
      input = int(raw_input())
   elif input >10:
      print 'error'
      print 'Please enter a number (from 1 to 9):'
      input = int(raw_input())
   
   else:
      
      result = input * value
      value = result
      counter = counter +1
      zahlenliste.append(input)
        print 'Please enter a number (from 1 to 9):'
               
   
   
print 'You have reached a value over 50.'
print '\n''Anzahl der getaetigten Eingaben'
print counter
print 'Welches war die kleinste Zahl, die du eingegeben hast?'
print min(zahlenliste)
print 'Welches war die groesste Zahl, die du eingegeben hast?'
print max(zahlenliste)
Last edited by Mekire on Sun Oct 27, 2013 12:33 pm, edited 1 time in total.
Reason: First post lock. Code tags. Please read the "New Users" thread.
djeasily
 
Posts: 1
Joined: Sun Oct 27, 2013 12:19 pm

Re: please help me with this little "number program"

Postby Kebap » Sun Oct 27, 2013 1:08 pm

Hi and welcome to the forums and python! :)

You can just save the old input in a variable, then compare to the new input.

Also, I found a problem with your code: If somebody enters a wrong number, she is asked to input again. If the new input is wrong again, what happens?
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: 387
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: please help me with this little "number program"

Postby emmauk » Sun Oct 27, 2013 1:25 pm

I'm new to Python too but I believe you can do
Code: Select all
if input in zahlenliste:
 # to check if it appears at all, or
zahlenliste[-1] # to see the last entry

I hope that helps
emmauk
 
Posts: 7
Joined: Sat Oct 26, 2013 5:23 pm

Re: please help me with this little "number program"

Postby hrs » Sun Oct 27, 2013 6:57 pm

input is the name of a built in function so you should use another name for your variable.
hrs
 
Posts: 86
Joined: Thu Feb 07, 2013 9:26 pm


Return to General Coding Help

Who is online

Users browsing this forum: Baldyr, Google [Bot] and 3 guests