Hi I was reading the thread http://www.daniweb.com/forums/thread12326.html which is about getting user input from a user in python.

So I thought I would write something to tst it since I haven't used python in a while so I wrote a basic program to calculate netpay.

hours = raw_input("Enter Hours Worked: ")
gross = (hours * 12)
netpay = ( gross - ( gross * 0.15))
print "Your net wage is" $netpay

However I cannot get user input as the program doesn't wait for the user to input data just processes through, so how do you ge the program to stop for the user when getting input?

Perhaps it is just a mistake:
raw_input - takes a string, you need an integer. use just
hours = input("Here Hours...")
After print "Your net wage is", netpay (You are missing a comma after string)

Thanks got it working also needed a pause to see output. is there a way to enforce output to have 2 decimal places?

import time
hours = input("Enter Hours Worked: ")
gross = (hours * 12)
netpay = ( gross - ( gross * 0.15))
print "Your net wage is $",netpay
time.sleep(2)

1. on line 4.... You are missing a coma.

print "Your net wage is", $netpay

2. This is python not php/perl

no need for

$netpay

just

netpay

Unless net pay is a template of which i dont think so. :)

Output with two numbers after comma? Try this:
f - for float point
d - for decimal
s - for string

print "netpay %-.2f" %(netpay)

I am using notepad++ and without time module output flashes through without being read.

notepad++ isn't an ide I am saving output to desktop and running program from outside ide.

I cannot get decimal too work..still trying.

Edited 5 Years Ago by flebber: n/a

just try Idle or pydev/Aptana or netbeans.

They are all free and learning will be a breeze.

what OS are you on now?
:)
;)

Edited 5 Years Ago by richieking: n/a

Trying everything with decimal to get it too work but can't get it to work this is my last attempt following http://docs.python.org/library/decimal.html

import time
from decimal import *
Decimal(2)
hours = input("Enter Hours Worked: ")
gross = (hours * 12)
netpay = ( gross - ( gross * 0.15)) 
print "Your net wage is $", Decimal('netpay')
time.sleep(4)

Edit: Xp and 7. with a ubuntu box also.

And

import time
from decimal import *
hours = input("Enter Hours Worked: ")
gross = (hours * 12)
netpay().prec = 2
netpay = ( gross - ( gross * 0.15)) 
print "Your net wage is $", netpay
time.sleep(4)

Edited 5 Years Ago by flebber: n/a

Because we should be defining types before the math otherwise ( not likely in this example) get an incorrect result as an effect of rounding.

So how can I tell all my numbers in function to be 2 decimal places?

Edit maybe I can't define a varibale as 2 decimal places

Python figures out what type a variable is and keeps track of it internally.

from http://diveintopython.org/getting_to_know_python/declaring_functions.html

Edited 5 Years Ago by flebber: n/a

Like this no need to use time or decimal module.
Set upp notepad++ correct or use a good ide editor for python like pyscripter or pydev/SPE IDE
http://code.google.com/p/pyscripter/
http://pythonide.blogspot.com/
http://pydev.org/

hours = float(raw_input("Enter Hours Worked: "))
gross = hours * 12
netpay = gross - (gross * 0.15)
print "Your net wage is %.2f " % netpay

The code dos what you want it stop for user_input,and print out answer with 2 decimal places.
If it dos not,notepad++ is the problem.
http://www.daniweb.com/forums/thread151270.html
http://cse.ucdavis.edu/~chaos/courses/nlp/Software/Windows/npp.html

Edited 5 Years Ago by snippsat: n/a

This article has been dead for over six months. Start a new discussion instead.