[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Trying to write a very basic payroll program in python, and feel
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 37
Thread images: 4
File: noPhoto.jpg (10 KB, 433x500) Image search: [Google]
noPhoto.jpg
10 KB, 433x500
Trying to write a very basic payroll program in python, and feel like a fucking retard right now.

Just want the fucker to run until I tell it to stop, but it never runs. Code is latest I've tried thinking of.

name = 0
if name != 0:
name = input('Enter employee name: ')
rateofpay = int(input('Enter employee hourly rate: '))
hours = int(input('Enter total hours: '))
overtimerop = (int(hours * 1.5))
othours = int(input('Enter total hours beyond 40: '))
grosspay = (hours * rateofpay) + (othours * overtimerop)
print()
print('Employee: ', name)
print('EE rate of pay: ', rateofpay)
print('EE total hours: ', hours + othours)
print('EE total gross wages: ', grosspay)
else:
name == 0
print('You are now exiting the program.')
>>
>>55625214
OP, I wrote the equivalent of this in QBASIC, with no formal training, no google and no help other than the built-in help, when I was 9 years old.

If you're struggling with this, maybe you should give up programming.
>>
>>55625267
I find that hard to believe

Also, don't be a gigantic faggot, don't respond if you don't have an answer.
>>
>>55625312
>I find that hard to believe
You don't need to, I still have the program :^)

https://0x0.st/mVv.txt
>>
>>55625214
>name = 0
>if name != 0
wew lad... https://wiki.python.org/moin/WhileLoop
>>
>>55625380
I ain't clicking that shit, nigga.
>>
>>55625380
>https://0x0.st/mVv.txt
print "Good ok now enjoy using Checkbook Manager v1.4!"
;****@*%*�*&*=*#*"*�*�*~*+*'*<*>*^*�****OPTIONS STILL COMING!!!!!****@*%*�*&*=*#*"*�*�*~*+*'*<*>*^*�****

o i am laffin
>>
>>55625214
"Name equals 0"
"If name does not equal zero"

You don't know what you are doing
>>
>>55625214
OP if this is not bait I will help you write this program
>>
>>55625267
No one here gives a shit, Go stroke your ego elsewhere.
>>
>>55625464
Nah that's ok. Clearly since I am not a l33t h4x0r like the rest of you fedora faggots I should find help elsewhere.
>>
>>55625214
If you want it to loop until you kill it you will need to put either a for loop or a while loop in there somewhere.

I can write you one in java if you want but you will have to pay me some shekels because i don't work for free.

I don't really know much about python.
>>
>>55625530
BOO HOO I CAN'T HANDLE CRITICISM
>>
>>55625419
if you enjoy this sort of shit

https://0x0.st/mV6.txt
>>
>>55625555
randomize timer
cls
print "Person's Program 2000
print " von, Anon Productions Inc."
print
print "Dieses Programm rechnet die ersten 20 Primzahlen aus!"
print "Bitte haben Sie einen Moment geduld."
zahl = 1
1
print zahl
2
zahl = zahl + 1
do for zahl
divider = zahl - 1
check = zahl % divider
if check = # then goto 2
>>
>>55625555
Check'd
>>
File: SNoopy_dog.jpg (99 KB, 640x640) Image search: [Google]
SNoopy_dog.jpg
99 KB, 640x640
>>55625214
>enter total hours
>enter total hours past 40
>>
I hadn't realize that 4chan could both be helpful and choke on gigantic cocks at the same time. Thanks guise!
>>
>>55625628
What if u get paid on 2 weeks and worked 88 hours total. That could be 40 + 48 or 1 + 87, which would get u different money
>>
>>55625214
>name = 0
>if name != 0 ....
>why doesn't it run
gee i fucking wonder why. you set name to 0 and then do the rest of it only if name is not 0.
>>
>>55625530

Since you declared name to be 0 at the top of your program, the code inside the if statement will never be run (as name will never not equal 0). Instead, use a while loop.

# Function that performs payroll calculation
#
# Function syntax:
# def doSomething(employee, business)
# ^name ^parameters (optional)
#
# You must define functions before they are used
def calculate(): # Takes no parameters
# Numbers with decimals are floats (floating-point), not int
payRate = float(input('Enter employee hourly rate: '))
otPayRate = float(payRate * 1.5)

hours = int(input('Enter regular hours: '))
otHours = int(input('Enter overtime hours: '))
pay = (payRate * hours) + (otPayRate * otHours)

print()
print('Employee: ', name)
print('EE rate of pay: ', payRate)
print('EE total hours: ', hours + otHours)
print('EE total gross wages: ', pay)

# While structures loop forever as long as a given condition is met. Syntax:
# while [condition]:
#
# As long as [condition] evaluates to True, the loop will continue unless
# manually stopped with the `break` keyword.
#
# In this case, `True` will always evaluate to True, so this structure will loop
# forever until `break` is called.
while True:
name = input('Enter employee name: ')
# Since name is a string, compare it to "" (empty string), not 0 (integer)
if name == "":
# If name is empty, exit. `break` stops the while loop
print('You are now exiting the program.')
break
else:
# Name is not empty: perform calculation...
calculate()
# ...and loop again (break is not called)
>>
>>55625214
I don't really know python but something like this may work.

import sys

while (True) {
name = 0
if name != 0:
name = input('Enter employee name: ')
rateofpay = int(input('Enter employee hourly rate: '))
hours = int(input('Enter total hours: '))
overtimerop = (int(hours * 1.5))
othours = int(input('Enter total hours beyond 40: '))
grosspay = (hours * rateofpay) + (othours * overtimerop)
print("\n")
print('Employee: \n', name)
print('EE rate of pay: \n', rateofpay)
print('EE total hours: \n', hours + othours)
print('EE total gross wages: \n', grosspay)
else:
name == 0
print('You are now exiting the program.\n')
sys.exit(0)
}
>>
File: astraalikuumotus.jpg (6 KB, 172x200) Image search: [Google]
astraalikuumotus.jpg
6 KB, 172x200
>>55625578
>>
>>55625788
Wrong.

>name = 0
>if name != 0

The name input prompt will never be run.
>>
>>55625788
>I don't really know python
Very fucking obvious
>>
You're welcome, OP.

def op_is_faggot(years_of_faggotry, size_of_faggotry):
"""Check if OP is a faggot

Arguments:
years_of_faggotry {int} -- How many years been fag
size_of_faggotry {int} -- How big fag is OP

Returns:
bool -- is fag or not fag
"""
if int(years_of_faggotry) == 0 and int(size_of_faggotry) == 0:
return False
return True # assume that OP is faggot


op_is_a_faggot = True

while op_is_a_faggot:
print('OP, you are a faggot.')
faggotry_years = input('How many years have you been a faggot? ')
faggotry_size = input('How big of a faggot are you, OP? ')

op_is_a_faggot = op_is_faggot(faggotry_years, faggotry_size)


print('Congratulations, you are not a faggot.')
>>
>>55625691

>which would get u different money

And that's perfectly fine, because in one week you had a shitton of overtime hours and those are worth more. Dumbass.
>>
>>55625780
>code box isn't 80 characters wide
What the fug
>>
>>55625804
idgaf it's a useless language soon to be replaced by Rust anyway.
>>
>>55625846
But we don't know the scope of what OP's using this proggy for. What if he wants to calculate wages for 2 months? It would be silly to assume every week only had 40 hours like I'm thinking you're implying he should do.
>>
>>55625873
>soon to be replaced by Rust
>scripting language soon to be replaced by a compiled language meant to replace C
Stop while you're behind, anon.
>>
This is probably OP's first program. Jesus christ, cut him a break.
>>
>>55625902
b-b-but how am i supposed to look like i have any programming knowledge whatsoever if I can't shit on beginners?
>>
>>55625902
Well if that's true he should turn in his computer to the authorities and give up.

He doesn't have the cognitive capacity to master programming if he can't step through that tiny little bit of code and see why it doesn't run.
>>
>>55625214

>l like a fucking retard right now.

Read your sources, damnit..

The "If"-statement does ONE THING for ONE TIME then goes on.

What you want is probably this:

name = ''
while name.strip() != 'q':
name = raw_input("Enter employee name (or q for Quit): ")

print('You are now exiting the program.')
>>
File: kyoko.gif (524 KB, 500x620) Image search: [Google]
kyoko.gif
524 KB, 500x620
>>55625530
>He asked for help on 4chan and got upset when people made fun of him
It's like you don't know where you are
>>
>>55625780
Makes perfect sense. Much appreciated, anon.
Thread replies: 37
Thread images: 4

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.