python newbie
d
dwelch at localhost.localdomain
Thu Jan 8 18:01:13 EST 2004
Rene Pijlman wrote:
> broebel:
>>first problem is the fact that I started out with a little program who was
>>part of a course but the problem is when I launch the program. I don't
>>have the time to see the result because the screen closes immediately.
>>Can anyone explain what's happening.
>
> The program started, did what it had to do and then terminated :-)
>
> "1 How do I run a Python program under Windows?"
>
http://www.python.org/doc/faq/windows.html#how-do-i-run-a-python-program-under-windows
>
Worked fine for me on Linux... made two suggested changes: 1) use
raw_input(), not input(), 2) check user input for errors. Sorry, I don't
know how to say "Enter a number between 0 and 500" in whatever language
this is in (German?)
#!/usr/bin/env python
while 1:
bedrag = raw_input ( 'Geef bedrag tussen 0 en 500 eurocent: ' )
try:
bedrag = int( bedrag )
except ValueError:
print "Enter a number between 0 and 500"
else:
if bedrag < 0 or bedrag > 500:
print "Enter a number between 0 and 500"
else:
break
for munt in 200, 100, 50, 20, 10, 5, 2, 1 :
aantal = 0
while bedrag >= munt :
aantal = aantal + 1
bedrag = bedrag - munt
if aantal > 0 :
print aantal, 'x', munt
--
/d/
More information about the Python-list
mailing list