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

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




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

what ide are you using?

it must stay up.
no need for time module.

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.

just try Idle or pydev/Aptana or netbeans.

They are all free and learning will be a breeze.

what OS are you on now?

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 *
hours = input("Enter Hours Worked: ")
gross = (hours * 12)
netpay = ( gross - ( gross * 0.15)) 
print "Your net wage is $", Decimal('netpay')

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


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

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

Just format your print like this

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.