Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows python,what am I doing wrong?

Status
Not open for further replies.

ohhdamn

Technical User
Jul 5, 2001
17
0
0
US
I just downloaded a windows freindly python package,Im new to programming and python has a simple syntax that I think is easy to understand.I want to try out some of my baby skilz but the program doesnt run right,heres my program:

print"simple"
a=input("speed?")
b=input("distance?")
print"itll take",b/a,"to go that far"

When I run it the "speed?" prompt comes up but nothing after that,no matter how many times you hit enter "distance?" never prints.
Is it my program or do you think its windows jealousy?



 
Its not the program I just clicked the file in my documents menu and it ran but closed the window the second it printed the last line.But still does not work if I try "run module"in the edit window.
 
well, try not to run it from the console. do it with in a new window. after u save and wanna compile, click Edit -> Run Script. it should work...
 
Using input() is fine, since your are asking for an integer as input from the user.

Your code should look like this...

print"simple"
a=input("speed?")
b=input("distance?")
print"it\'ll take",float(b)/float(a)*60," to go that far"

notice on line 1 instead of using a/b I used
float(a)/float(b)*60

This is because if you do not use a float then pyhton (as well as C++ or Java) will round the number and fraction down to the nearest whole number. I also added *60 since I assumed you wanted the result in minutes.

if you are still printing the ouput to the console and want a chance to see the answer try adding

from time import sleep #Use this at the beginning of your program and
sleep(3) #at the end, where you can replace 3 with whatever number of seconds you want the program to pause before it finishes.


I am a python newbie as well, I am still trying to learn how to write rudimentary programs, but it's a lot of fun!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top