python newbie

B

broebel

hey,

I'm a newbie in the programming world.
I just started and already I'm in a whole lot of problems.

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.

thanks in advance

me,

# Een bedrag gepast betalen met zo min mogelijk euromunten

bedrag = input ( 'Geef bedrag tussen 0 en 500 eurocent: ' )

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
 
R

Rene Pijlman

D

d

Rene said:
broebel:

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
 
A

Anthony Borla

broebel said:
hey,

I'm a newbie in the programming world.
I just started and already I'm in a whole lot of problems.

And you'll probably experience a whole host more - welcome to the wonderful
world of programming ;) !!!
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.
<SNIP CODE>

You are obviously not launching the interpreter from a console window. Thus,
launching the interpreter forces a new console window to be opened, your
program executes, and it then closes because it has finished.

Possible remedies allowing you to view your program's output:

* Launch interpreter as you have been doing, but add a line
such as:

raw_input("Press a key to continue ")

at the end of your code to prompt for a key press before
exiting, and closing the console window

* Start using the intepreter from a console window i.e. start
using the command line. All generated output will appear
on the same console.

Since you are in a course [?] I'd recommend asking your
instructor about suitable tutorials for doing this

I hope this helps.

Anthony Borla
 
J

Joe Francia

d said:
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?)

You're a Python user and you don't recognize Dutch?!?! For shame... ;>)
 
B

broebel

thanks anthony,

that's what I really wanted to know.

Anthony Borla said:
broebel said:
hey,

I'm a newbie in the programming world.
I just started and already I'm in a whole lot of problems.

And you'll probably experience a whole host more - welcome to the wonderful
world of programming ;) !!!
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.
<SNIP CODE>

You are obviously not launching the interpreter from a console window. Thus,
launching the interpreter forces a new console window to be opened, your
program executes, and it then closes because it has finished.

Possible remedies allowing you to view your program's output:

* Launch interpreter as you have been doing, but add a line
such as:

raw_input("Press a key to continue ")

at the end of your code to prompt for a key press before
exiting, and closing the console window

* Start using the intepreter from a console window i.e. start
using the command line. All generated output will appear
on the same console.

Since you are in a course [?] I'd recommend asking your
instructor about suitable tutorials for doing this

I hope this helps.

Anthony Borla
 
D

djw

Joe said:
You're a Python user and you don't recognize Dutch?!?! For shame... ;>)

Well, I was only off by one country - not too bad for someone who took 4
years of high school Spanish and can hardly speak a word of it.

I was looking at the code that I proposed to the OP, and wondered if this
wasn't better:

#!/usr/bin/env python
while 1:
bedrag = raw_input ( 'Geef bedrag tussen 0 en 500 eurocent: ' )
try:
bedrag = int( bedrag )
if bedrag < 0 or bedrag > 500:
raise ValueError
except ValueError:
print "Enter a number between 0 and 500" # In DUTCH, of course!
else:
break

# ... etc.


Is this good style, that is, to put multiple items inside a single try:
except: else: block? Seems more compact and tidy than my first try.

-d
 
B

broebel

Just like you don't speak dutch, I don't write python (that's a good reason
to learn, isn't it) so I'm not trying out your proposal to see wheather it
works or not.
I kept it aside to check as soon as I understand more of the language. So
thanks any way.
btw is there a special reason why someone should speak dutch to programm in
python.?
 
F

Francis Avila

broebel wrote in message said:
Just like you don't speak dutch, I don't write python (that's a good reason
to learn, isn't it) so I'm not trying out your proposal to see wheather it
works or not.
I kept it aside to check as soon as I understand more of the language. So
thanks any way.
btw is there a special reason why someone should speak dutch to programm in
python.?

Guido van Rossum created Python, and is currently its BDFL (Benevolent
Dictator For Life). He's Dutch. It's a sort of an inside joke that Python
makes sense if you're dutch (type 'import this' into an interactive Python
prompt).
 
G

Gerrit Holl

Francis said:
Guido van Rossum created Python, and is currently its BDFL (Benevolent
Dictator For Life). He's Dutch. It's a sort of an inside joke that Python
makes sense if you're dutch (type 'import this' into an interactive Python
prompt).

So he'r really the VDVL, Verlichte Despoot Voor het Leven :)
Shouldn't the Zen of Python be translated?

De Zen van Python, door Tim Peters
vrij vertaald door ondergetekende

Mooi is beter dan lelijk.
Expliciet is beter dan impliciet.
Simpel is beter dan complex.
Complex is beter dan gecompliceerd.
Plat is beter dan genest.
Dun bezaaid is beter dan dicht bezaaid.
Leesbaarheid telt.
Speciale gevallen zijn niet speciaal genoeg om de regels te overtreden.
Maar de praktijk gaat voor de zuiverheid.
Foutmeldingen horen nooit genegeerd worden.
Behalve expliciet.
Weersta de verleiding tot raden bij onduidelijkheden.
Er hoort een - bij voorkeur slechts een - duidelijke oplossing te zijn.
Maar die lijkt misschien niet meteen duidelijk voor niet-Nederlanders.
Beter nu dan nooit.
Maar vaak is nooit beter dan *nu meteen*.
Als het moeilijk is uit te leggen, is het een slecht idee.
Als het makkelijk is uit te leggen, is het misschien een goed idee.
Namespaces zijn een ... goed idee -- daar doen we er meer van!

groetjes,
Gerrit :).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,490
Latest member
Finplus

Latest Threads

Top