#๐Ÿ”’ Help with code:

401 messages ยท Page 1 of 1 (latest)

twilit rampartBOT
#

@hard sage

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

honest sandal
#

Can you show the code and the input you entered and the output you get and the expected output you're supposed to get?

rich frost
#

!code

twilit rampartBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

honest sandal
#

!pastebin if that's easier for you

twilit rampartBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

honest sandal
#

I ran your code and got this:

Number of pizza orders: 43
Number of salad: 7

Pizzas ordered:  43
Pizza cost: $ 687.57
Salad cost:  55.93
Total: $ 743.5
Discount: $ 103.13550000000001
Delivery fee: $ 20
Total amount: $ 660.3645

What are you supposed to get?

hard sage
#

godbless I deleted it to fix it once more thank you sir. My outputs are suppose to be

Pizzas ordered: 11
Pizza cost $ 175.89000000000001
Salad cost $ 55.93
Total $ 231.82000000000002
Discount $26.3835
Delivery fee $ 20.0
Total amount due $ 225.43650000000002

rich frost
#

supposed to be?

hard sage
#

Guranteed to be

rich frost
#

man that is painful

hard sage
#

listen

#

im having a stroke

rich frost
#

I'm assuming the float error is supposed to show something?

hard sage
#

it took two hours to type this and im still crying im a freshman at all of this ๐Ÿ˜ญ let me resend the whole code correctly apolgiese for my pure ignorance

honest sandal
#

Just use a pastebin

#

!pastebin

twilit rampartBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

honest sandal
#

Then you won't have to worry about code formatting in Discord

hard sage
hard sage
#

Thats why it took long

#

mb

#

Ik the else code in 28 is useless

#

it was my attempt to see if that would work ive been trying for so long

#

I love that i chose this as my profession but I can do a lot of nsfw jokes to myself right now

honest sandal
# hard sage my brain is fried i read it wrong somehow

ok so explain this line for me:

print("\nPizzas ordered: ", whole_pies)

It seems to take the value from:

whole_pies = (total_slices + slice_pp - 1) // slice_pp

But that doesn't reflect what the actual print statement said. Especially since the answer is from the input:

num_pizzas = int(input("Number of pizza orders: "))
hard sage
rich frost
#

newline

hard sage
#

^^^

night dew
#

thanks

honest sandal
hard sage
#

ik the salad codes are correct for sure

honest sandal
hard sage
#

its the stupid pizza that isnt

#

๐Ÿ˜ญ

honest sandal
#

So if I, a customer, entered my order of pizzas that I want is 43, then the display output should display 11 pizzas?

hard sage
honest sandal
#

Seems confusing, no?

hard sage
#

yes it 100% is.

honest sandal
#

Is this an assignment or exercise or something?

hard sage
#

yes assignment exercise. But Im not in here to simply ask for cheats and answer. Im really crap out of luck and so deeply lost

honest sandal
hard sage
#

to answer

honest sandal
hard sage
#

yes ofcx

honest sandal
#

Just to make sure you understood the assignment

night dew
#

@honest sandal offtopic, but could you attempt helping me out with selenium if u are available after this? Sorry for bothering

honest sandal
night dew
#

No worries lol

hard sage
#

Write a Python program that will determine food costs for the KSU CCSE hackathon.
The hackathon will have pizza and salad option. The program should ask the number of
people who ordered pizza and the number of people who ordered a salad. Each person
who orders pizza is allocated three (3) slices of pizza. Each salad costs $7.99 per
person. Each whole pizza costs $15.99 and has 12 slices per pizza. Only whole pizzas
can be ordered.

If more than ten (10) whole pizzas are ordered, then there will be a 15% discount to the
pizza cost. If more than 10 salads are ordered there will be a 15% discount to the salad
cost. The delivery charge is 7% of the entire order prior to discounts or $20 minimum.
Display the number of each type of meal ordered (input is not considered as a display/output). Determine and display the number of whole pizzas needed.

Display
the cost of the pizzaโ€™s and display the cost of salads (before any discounts). Display the
discount amount and delivery charge. Finally display the total amount due. You do not
need to round or truncate your output.

#

Example of input
Number of pizza orders 43
Number of salad orders 7

Example of output
Pizzas ordered: 11
Pizza cost $ 175.89000000000001
Salad cost $ 55.93
Total $ 231.82000000000002
Discount $26.3835
Delivery fee $ 20.0
Total amount due $ 225.43650000000002

#

if you want me to fix the post to be correct in discord and not look deformed i gotchu]

honest sandal
#

oh "pizza orders" being the number of people ordering pizzas.

hard sage
#

I clearly didnt explain that as it states my apologies Im rereading what I typed

honest sandal
#

Such a weird assignment

hard sage
#

it's been mind screwing me

#

and I couldn't neccesiarly import math

#

and do all that

#

I had to do it like this rather

honest sandal
#

So 1 person order is 3 slices.

#

1 pizza is 12 slices

#

So you need at least 4 people to order for 1 whole pizza

#

And that costs $15.99

#

If you have more than 10 pizzas (or at least 40 people ordered), then there will be a 15% discount to the pizza cost

#

Ok well, let's focus on the pizzas ordered

hard sage
#

sir yes sir! lol thank you again for your time btw. but continue im reading

honest sandal
#

OK so assume that its 40 people who ordered pizza, that should get us the 10 pizzas. that doesn't get us the 15% pizza discount, right?

#

@hard sage

hard sage
#

If more than ten whole pizzas are ordered the discount will be added

#

so then yes

honest sandal
#

ok

#

Explain this line for me:

total_slices = num_pizzas * slice_pp
whole_pies = (total_slices + slice_pp - 1) // slice_pp
hard sage
#

One whole pizza pie = the total slices (number of pizzas * slice per person)

#

-1 // slice per person

#

essentially

honest sandal
#

So if number of pizzas is 40, what is slice per person?

hard sage
#

13.3333 but since you cant have a fraction to it

#

simply 13

#

cause 40 (number of pizzas) / by 3 (which is the 3 slices for what each person gets)

#

SORRY

#

slice per person is 3

#

but doing 40/3

#

makes 13 people getting those slices

honest sandal
#

yeah its not supposed to be dividing by slice per person

#

think about it

#

1 whole pizza is supposed to be 12 slices

#

which variable has 12 in it?

hard sage
#

pizza_slices

honest sandal
#

so the formula should be?

#

I'm saying this line's formula is wrong

whole_pies = (total_slices + slice_pp - 1) // slice_pp
#

Correct it

hard sage
#

real fast you did '''...''' to make it into the code?

honest sandal
#

!code instructions below

twilit rampartBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

hard sage
#

gotchu

honest sandal
#
print("Like this")
hard sage
#

i feel smart for doing that right okay typing rn

#
print("pizza_slices + slice_pp -1) // slice_pp
#

?

honest sandal
#

nope

hard sage
#

ok then

honest sandal
#

well, you got the code format correctly

#

but your formula is still wrong

hard sage
#

Oh i thought format was incorrect

#

print("pizza_slices * slice_pp -1) // slice_pp
I dont wanna act as if im simply guessing but it's fully not clicking uhm idk this other way would be correct instead then tbh.

#

Im gonna scroll up

#

and reread rq

#

two seconds before answer

#

whole_pies = (total_slices + slice_pp - 1) * slice_pp

its not suppose to be dividing but the format is correct

#

so then that?

hard sage
honest sandal
hard sage
#

ok ok

hard sage
honest sandal
#

I'll give you a hint, replace each "variable" with the "value" that you set

#

see if that makes sense

hard sage
#

MMMMMMMMM

honest sandal
#

Sorry I gtg

hard sage
#

FUHHHHHH

#

can u just give me this part cause im stil lthinking

#

at least with that

#

I can try to

#

go from there

#

i think

honest sandal
#

total_slices is correct. But the whole_pies needs to be fixed

#

Think of 43 * 3 // 12

#

good luck!

hard sage
#

ok ok. Sir really thank you for ur time

#

please if u come back!

#

CHECK UP
I BEG

#

๐Ÿ™ thank you man

rich frost
#

ping me to post my version when you get a final answer (it will not follow the instructions exactly in the output but that's easily changeable. Instead I will give sensical output with only two decimal digits)

hard sage
#

(whole_pies = (total_slices * slice_pp) // pizza_slices @rich frost my bad just to clarify you mean when I finish all of it or like this step agent Q left me with. Cause I do believe it will be whats in print

rich frost
#

I mean finish everything

#

cuz I will be posting a whole solution

hard sage
# rich frost cuz I will be posting a whole solution

I dont wanna bs that shi is gonna take the whole night as Ive been tweaking out since I got stuck here. I've been in constant loops so I wouldn't be able to properly get into the end as fast as u did my work ๐Ÿ˜ญ ๐Ÿ˜ญ I know teaching is only for the few but can you put me on and help a little

#

so I dont sit here lost

#

if not all good but just truthfully thats where im at rn

#

but i get wym

#

asd the whole situation

#

would essientally show all

#

just yk i cant get to all rn ๐Ÿ˜ญ as im messing up

rich frost
#

uh

#

is the example just wrong?

#

11 * 12 = 132

#

oh wait nvm lol

hard sage
#

AHHH i thought that too i've tried to simply

rich frost
#

burh

hard sage
#

put the input as 11

#

for pizza

#

but he

#

wants it as

rich frost
#

I just read wrong

#

too many numbers

hard sage
#

LMAO ik ๐Ÿ˜ญ

rich frost
#

the price is 15.99

hard sage
#

mhm for a whole pizza yeah

hard sage
rich frost
#

just threw a bunch of round(..., 2) in lol

#

I was doing that for the salads to get proper cents, but yeah doing it for pizzas now

hard sage
#

appreciate gang if it goes well please lmk if you could work this out with me so I can be done

rich frost
#

yeah got it all working now

#

with proper cents vs the shitshow that is those inaccurate floats

#

the trick to make this readable is to define lots of constants, and use descriptive variable names

hard sage
#

So I should rechange some

rich frost
#

e.g. I have those constants

PIZZA_PRICE = 15.99
SALAD_PRICE = 7.99
DISCOUNT_THRESHOLD = 10
DISCOUNT_RATE = 0.15
DELIVERY_RATE = 0.07
MINIMUM_DELIVERY_CHARGE = 20.00
SLICES_PER_PIZZA = 12
#

although i did do this

# Each person who orders pizza is allocated three (3) slices of pizza.
pizza_slices_desired = pizza_orders * 3
#

because idk

hard sage
hard sage
rich frost
#

can you post your whole current code?

hard sage
#

mhm

hard sage
#

I went to change it

#

but after I did that

#

It was still wrong ik there is more though

rich frost
#

I think what you should do is making the constants SCREAMING_SNAKE_CASE

#

that will make it clearer when you are using a constant

#

I'm pretty sure this is wrong, but didn't think about it super thoroughly

whole_pies = (total_slices + slice_pp - 1) // slice_pp
rich frost
#

oh I think I see how it works now

#

if it's exactly a multiple of 12, then adding 11 and floor-dividing will give the correct answer still

#

and if it's one more than a multiple of 12, then adding 11 will make it to the next multiple of 12

#

I just used math.ceil

hard sage
#

thats the catch

#

i can't import

#

math

#

and use math.ceil

#

so when im trying all of this

#

im screwed

#

thats why we are here

#

and im trying to do all this bs

hard sage
rich frost
#

well you only gotta use ceil once so no worries, that is a fine substitute

#

and it looks smort

hard sage
#

ik ik but I mean

#

the professor

#

wasnt includign all that

#

so if I do that

rich frost
#

k

hard sage
#

yeah

#

mb tho ik what you mean gang really

#

could u help me the long hell way?

rich frost
#

ok so that part is fine then

#

continuing

hard sage
#

appreciate and to change that one line u said was wrong its

rich frost
#

no it's not wrong it's fine

#

I just didn't understand it at first

#

ok this is semantically wrong

if num_salads > discounted_pizza: ...
#

what I did is name that variable DISCOUNT_THRESHOLD

#

then it applies in meaning to both items

hard sage
#

ok ok

#

well in that case how would we change the formulas to make the output finally correct? I did change it

rich frost
#

also you can do this

discount = 0
if whole_pies > DISCOUNT_THRESHOLD:
    discount += total_pizza_cost * discount_rate
if num_salads > DISCOUNT_THRESHOLD:
    discount += total_salads_cost * discount_rate
hard sage
#

two seconds running to restroom but im still here!!!

rich frost
#

1

#

2

#

where tf are you bro

hard sage
#

LMAO

#

boom

#

@rich frost

#

two seconds, minutes same shi

rich frost
#

hours

hard sage
rich frost
#

no

#

adding that value to the discount

hard sage
#

so how would that change much then? as keeping it equal too only and adding that value keep the same output?

rich frost
#

yes same output

#

just maybe more understandable as "totalling up the discount"

hard sage
#

Copy copy

rich frost
#

there is someone grading your work afterall

hard sage
#

Lmao

#

YES

#

cant have him lost

rich frost
#

ok the order in which you do things is confusing

hard sage
#

how so, what can I fix to make it understandable

rich frost
#

you make the values, then do something that depends on only those values later

#

after going through some other fluff

hard sage
#

rather, I could have them together and be much more neat you're saying? From my eyes, I only wrote all this way as his wants for each step but I'm grasping what your saying would help much better

rich frost
#

I think calling it the "total" pizza cost is kinda misleading

#

I feel like a total means everything in, like discounts and such

#

could just be me

#

maybe prediscount_pizza_cost or something

hard sage
#

^^^^

#

gotchu

rich frost
#

then total_prediscount_cost or something

#

immediately after

hard sage
#

what next would be better to fix?

rich frost
#

I think this is wrong

total_pre_discount = pre_discount_charge - (pizza_discount + salad_discount)
#

why would the prediscount total incorporate the discounts?

hard sage
#

I saw it as to connect to the entire total of the calculations with the codes up at 32-34. But what woudl be better instead

#

plus after I wanted to connect it with the delivery fee

#

to add it as like the final total sum

#

but yes sounds too much fluff

#

what would be better then? @rich frost

#

remember a lot of this is new to me so as I been learning codes some is simply

#

rewriting step by step when im sure it can be abbreivated

#

and with these tweaks to make it less fluff, will it make me setup my output to be simpler shown and the same the example output

#

cause thats what is scaring me mostly

#

we use an app where the AI reads it and makes sure it gives the correct output

#

so sometimes im not sure if he is grading it fully in each code writing

#

which is why im more scared

#

to fix the output problem

#

but please this advice

#

helps more for future coding

#

@rich frost

rich frost
#

dang bro, use shift+esc

#

this is hard to read

#

give me a minute

hard sage
#

๐Ÿ˜ญ DAYUM SPARE ME

#

my bad my bad

#

copy

#

Im here twin let me know whenever

rich frost
hard sage
rich frost
#

ok wait I see

hard sage
#

but it is infact messy

#

the more im peeping it

rich frost
#

you worded it bad

#

total_prediscount is wrong

#

it is the total with discount

hard sage
#

LMAO

#

edited it rn

#

now its total_prediscount

rich frost
#

what

#

it already was that

hard sage
#

but it had an extra _

#

which wasnt needed

#

no?

rich frost
#

that is not what i was pointing out

#

that variable wording describes the wrong thing

rich frost
hard sage
#

Oh

#

then how would it be clear to change correctly without throwing extra?

rich frost
#

"throwing extra"?

hard sage
#

Without messing it up i mean

rich frost
#

erroring?

hard sage
#

yes

rich frost
#

what IDE are you using?

hard sage
#

pycharm

rich frost
#

ok lemme look up the pycharm equivalent of this

hard sage
#

๐Ÿ™ thank you bro ik i keep saying that but this shi been long

#

messing up too much ๐Ÿ˜ญ

rich frost
#

ok click on the variable name

#

then press F6

#

deselect "Search in comments and strings"

#

then replace with the new variable name

hard sage
#

okay now what I changed it to total_with_discount

rich frost
#

oki

#

is the code working btw?

hard sage
#

yes

#

code still got the green check

#

its just same situation

rich frost
#

ok so what are we talking about again

hard sage
#

exactly that

#

with the same input

#

now since i can't use import math & math.ceil

#

i need help with the proper equation

#

in order for it to work

rich frost
#

I thought you already got the equation?

hard sage
#

fixing that part

#

didnt change

#

the equation to work

rich frost
#

show output again

hard sage
#

Example of output

Pizza cost $ 175.89000000000001
Salad cost $ 55.93
Total $ 231.82000000000002
Discount $26.3835
Delivery fee $ 20.0
Total amount due $ 225.43650000000002 ```


MY output is putting this:
```Pizzas ordered:  43
Pizza cost: $ 687.57
Salad cost:  55.93
Total: $ 743.5
Discount: $ 103.13550000000001
Delivery fee: $ 52.045
Total amount: $ 692.4095```
#

it needs to match with top

rich frost
#

I think we should start from the beginning, and work through the code until we find the source of the first problem

#

pastebin current code

#

(the wrong amount of pizzas ordered)

hard sage
#

@rich frost

rich frost
#

you forgor

#

to remove your name and course

hard sage
#

LMAOOOOO

#

good looks twin

#

i just wanna get this done

#

its killing me deep

#

thank you

#

PLS dont expose me now LMAOOOOOOO

rich frost
#

I already found your address

#

/jk

hard sage
#

(legal reasons u said jk)

#

LMAO

rich frost
#

in-game

hard sage
#

LMAOOOOOO cant report now

rich frost
#

ok so

#

did you save your code?

hard sage
#

yes its saved

rich frost
#

AHA

hard sage
#

??

rich frost
#
whole_pies = (total_slices + slice_pp - 1) // slice_pp

slice_pp is wrong

#

whole pies are groups of 12

hard sage
#

OK OK I SEE YOU

#

what to change then?

rich frost
#

your poorly named pizza_slices

hard sage
#

YOOOOOOOOOOO

#

YOOOOOOOOOOOOOOOO

#

OK OK

#

WAIT

#

I CAN

#

LITERALLY

#

AND NON RELATIONSHIP OR ANY FREAKY FRISDAY WAY

#

CAN KISS

#

UUUU

#

SIR

#

I CAN SLEEP

#

YOU RELEASED MY TRAPPED SOUL

#

YOU SEXY MAN

rich frost
#

k

hard sage
#

LMAO TOO FAR

#

@rich frost GANG

#

means a lot

rich frost
#

power of reading

hard sage
#

ik crazy words were saved

#

but please

#

bottom of heart

#

thank you

#

I actually

#

was sad

#

for the longest

#

i ran around my room rn

#

my bed has been calling me

#

U R THE GOAT

rich frost
#

yw

hard sage
#

@rich frost

#

I could hug u no bs

#

goodnight me dear friend I loved this whole journey us 3 made

twilit rampartBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ Help with code: