#🔒 Help with my project please

413 messages · Page 1 of 1 (latest)

rain warrenBOT
#

@void sandal

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.

smoky tulip
#

???

snow berry
#

If you're trying to upload stuff it won't work.

#

You can paste code to the pastebin or paste it in a message here.

#

!paste

rain warrenBOT
#
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.

void sandal
#

i dont know why its not displaying my project

smoky tulip
#

Remember to follow the instructions in the pastebin

void sandal
#

!paste

rain warrenBOT
#
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.

void sandal
#

this is it guys.. any help would be nice

#

i just want to make the code a bit simplier

bleak trellis
#

a whole lot of ifs

void sandal
#

yeah

#

that makes it too much

bleak trellis
#

wait

void sandal
#

but that was the only thing i was able to think about..

smoky tulip
#

What’s the point of subjects += subjects?

#

Also, what’s your reasoning behind

for subject in subjects:

???

void sandal
smoky tulip
#

Yeah

#

So what you have is

#

for subject in subjects takes each value in subjects and assigns it to subject one at a time

#

And all break does is end that loop

#

But because English is the first value in subjects, it’ll always get used

void sandal
smoky tulip
#

What you want is:
for subject in subject:
if subject == English:
your code for English

void sandal
smoky tulip
#

then
elif subject == Spanish:
your code for Spanish

void sandal
bleak trellis
#

for subject in subjects:
mark = input(f"Please type in your mark for {subject}: ")
mark = int(mark)

#

do this ofr the ifs

#

!e
for subject in subjects:
mark = input(f"Please type in your mark for {subject}: ")
mark = int(mark)

smoky tulip
#

Also, just do
mark = int(input(
))

#

Saves a line here and there

bleak trellis
#
    mark = input(f"Please type in your mark for {subject}: ")
    mark = int(mark)```
#

make mark an array

void sandal
smoky tulip
#

@void sandal what @bleak trellis recommends is also suggested

#

Actually

#

Hmmm
 depends

#

If your grade values change between subject

#

Then it might not be the best

bleak trellis
#
i = 0
for subject in subjects:
    mark = input(f"Please type in your mark for {subject}: ")
    mark[i] = int(mark)
    i++```
bleak trellis
#

index of array

#

have you been taught array?

void sandal
smoky tulip
#

Definitely would not do it like that

bleak trellis
smoky tulip
#

If you’re gonna go down that route then better to use dictionaries

#

Which might be outside OPs scope for now

void sandal
#

stuffs getting confusing😆

bleak trellis
#

ok @void sandal do you have to use only if elses?

void sandal
#

nope..

#

the mission is to make the program run with as less lines of code as possible

bleak trellis
#

i can do it with arrays and explain it to you?

smoky tulip
#

Tempted to teach OP dictionaries

#




bleak trellis
smoky tulip
#

Alright

#

Let’s get to it

bleak trellis
#

if youd want to try go ahead

#

he barely knows arrays

smoky tulip
#

@void sandal you’re gonna need to be with me on this one

#

So

smoky tulip
#

You know basic variables

#

X = 5

void sandal
#

yes please

smoky tulip
#

So we tell the computer that when we ask for X, we want the number 5

#

But sometimes we wanna store a lot of numbers

#

And we don’t want to create a new variable for each

#

So we can use lists

#

These are shown by [ ]

#

Square brackets

void sandal
#

yes . please

smoky tulip
#

Now, we can save a lot of numbers to one variable

void sandal
#

yep

smoky tulip
#

X = [3533,6446,6433]

#

X can now store as many numbers as we want

#

However

void sandal
#

so now x equals three differrent numbers..

smoky tulip
#

We need to get these numbers out of X somehow

smoky tulip
void sandal
#

ok..

smoky tulip
#

Cause what if we want just one number?

#

So we can do that by calling the index

#

Going back to our example

#

X = [3533,6446,6433]

A list starts index at 0

#

So 0th number of X is 3533

#

1st is 6446 and so on

void sandal
#

yep

smoky tulip
#

We can access a list by the index and []

#

!e

X = [3533,6446,6433]
print(X[0])

rain warrenBOT
#

@smoky tulip :white_check_mark: Your 3.12 eval job has completed with return code 0.

3533
void sandal
#

makes sense

smoky tulip
#

See how here I set 0 within the square brackets and it gave me the 0th index in X

void sandal
#

yes please

smoky tulip
#

Ok

#

Now

#

We will learn dictionaries

#

They’re similar to lists

#

However

void sandal
#

ok..

smoky tulip
#

Instead of using numbered index, they can use named index

void sandal
#

ooooo

#

do you get to set the name or its already set

smoky tulip
#

A_Dictionary = {“Key” : “Value”}

smoky tulip
void sandal
#

a itsbin curly brackets

smoky tulip
#

So here I set the key of the dictionary to the string “Key”

smoky tulip
void sandal
#

ok..

smoky tulip
#

And the value is a string called “value”

#

Now if I want to get the value form the dictionary

#

I access it like a list

#

But use the key

#

So

void sandal
#

so the first value is the key and the last value is always value?

smoky tulip
#

!e
A_Dictionary = {'Key' : 3553}
print(A_Dictionary['Key'])

void sandal
#

is it like constant?

rain warrenBOT
#

@smoky tulip :white_check_mark: Your 3.12 eval job has completed with return code 0.

3553
smoky tulip
#

Separated by :

#

Value can be anything

#

Even a list

void sandal
#

ok..

#

wait so a list can be in a dictionary?

smoky tulip
#

!e
A_Dictionary = {'Key' : [255,5335,533]}
print(A_Dictionary['Key'])

rain warrenBOT
#

@smoky tulip :white_check_mark: Your 3.12 eval job has completed with return code 0.

[255, 5335, 533]
smoky tulip
#

But not to worry too much right now

void sandal
#

ok..

smoky tulip
#

We’ll focus on bare list and dicts

#

!e
A_Dictionary = {'Key' : 3553}
print(A_Dictionary['Key'])

rain warrenBOT
#

@smoky tulip :white_check_mark: Your 3.12 eval job has completed with return code 0.

3553
void sandal
#

ok..

smoky tulip
#

This is the key part

#

So you can make a dict

#

And set the key to the class

#

And the value to the score

#

To create an empty dictionary we do
Empty_Dict = {}

#

And to add we do
Emtpy_Dict[Key] = Value

void sandal
smoky tulip
void sandal
#

oh ok..

smoky tulip
#

So why don’t we start you off on your task

#

Got Python open nearby?

void sandal
#

im fired up

void sandal
#

in vs code

smoky tulip
#

Ok, let’s get a new Python script open

#

And copy over subjects

#

Just that list for now

bleak trellis
#

did you understand lists>

#

@void sandal

#

i did your code with lists if you wanna see and revise

void sandal
smoky tulip
bleak trellis
#

!paste

rain warrenBOT
#
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.

bleak trellis
void sandal
smoky tulip
#

@void sandal got the new Python script with subjects copied over?

void sandal
#

nope.. just a new python script

#

i should make a list with subjects?

smoky tulip
#

Ok, copy over
Subjects = [
]
From your old script

void sandal
#

oh ok..

#

done..

smoky tulip
#

Now, let’s make our for loop
for subject in subjects:
print(subject)

#

Just to make sure we’re seeing what we need

#

You can take screenshots and send them here

void sandal
#

ok..

#

done that

#

lemme take the screenshot

smoky tulip
#

Depending on your device you can use shortcuts or a snipping tool

void sandal
#

there..

smoky tulip
#

Perfect

#

So if you run it, it should print subjects line by line

#

Now

#

We want to do stuff with dictionaries

#

So we need to create an empty dictionary

void sandal
#

it does

smoky tulip
#

What do you wanna call it?
Student_Scores?

void sandal
#

yepp

#

thanks simple

#

that's*

smoky tulip
#

So on line 11 we need
Student_Scores = {}

#

As we want to create the dictionary outside our for loop

void sandal
#

done with that..

smoky tulip
#

@void sandal how do we add values to a dictionary?

void sandal
#

colon*

smoky tulip
#

That’s when you add the value manually

#

You’ll want
Dictionary_Name[Key_Name] = Value

void sandal
smoky tulip
#

That’s fine

#

So we know our dictionary name

#

What should each key be?

void sandal
#

thats what im think about..

#

subject_mark?

smoky tulip
#

What are we trying to get from the user?

void sandal
#

the subject mark

smoky tulip
#

The mark yes, but the mark of what?

void sandal
#

the mark of each subject..

smoky tulip
#

Exactly

#

So each key is a subject

void sandal
#

ok..

smoky tulip
#

So we in our loop add
Student_Scores[subject] = int(input())

#

As now each subject becomes a key

#

And the value is what the user inputs

void sandal
#

ok..

smoky tulip
#

Now, we want to customise the input

#

So the user doesn’t get confused

#

I see that you understand f-strings?

#

Why don’t we make the input an f-string

#

Let’s say the subject is English, what would the input message look like?

void sandal
void sandal
smoky tulip
#

Any message is fine, as long as it mentions the subject

void sandal
smoky tulip
#

Excellent

#

Why don’t we put that into the input()

void sandal
#

yay

void sandal
smoky tulip
#

Which you’ve done

#

So no worries

#

Now

void sandal
smoky tulip
#

After your for loop, unindented, why not add
print(student_scores)

#

And let me see what the code looks like

void sandal
#

ok..

#

i think theres a slight error somewhere

smoky tulip
void sandal
#

oh yeah

#

dumb me lol

smoky tulip
#

So copy paste line 13 after = on line 17

#

No worries

#

I make similar mistakes

void sandal
#

better now

smoky tulip
#

Perfect

#

Why not run the code

#

And enter some scores

void sandal
#

ok..

smoky tulip
#

See what the result looks like

#

Oh

#

Wait

#

@void sandal

#

Remove that break

#

You don’t need it

void sandal
#

oh ok..

#

lolz

#

thought it would be nice to add hehe

smoky tulip
#

XD

#

It would end your loop after 1 iteration

#

When we want the whole thing

#

Break is only when you want to get out of the loop early

#

Not needed in your case

void sandal
void sandal
smoky tulip
#

So you see your last output

#

That’s what student_scores looks like

#

With all your scores saved to each subject

#

Now

#

I’m gonna teach you the keyword “in”

#

But before that

#

Are there any subjects that have the same grading?

void sandal
#

it depends on the user's input

smoky tulip
void sandal
#

ok lol

smoky tulip
#

Well, like, is a 78 in English a B and is a 78 in Spanish also a B

void sandal
#

yeah

smoky tulip
#

So will a 90-100 always be an A regardless of subject

#

Ah ok

void sandal
#

the grades are the same for all subjects

smoky tulip
#

Gotcha

#

Ok

void sandal
#

but can you teach me like .. after everything can you teach me the one where the grades are not the same for each dubject.. only if you have time tho..

void sandal
#

thanks os much XD

#

so*

smoky tulip
#

For now, we’ll go with each subject

#

So, we need another for loop

void sandal
#

ok..

smoky tulip
#

So we need
for subject in subjects:

#

And now we’ll have
if 90 < student_scores[subject] <= 100:
print(f”You scored an A in {subject}”)

Can you tell me what the code above does?

void sandal
#

so basically idf the student got a score which is greater than 90 and less thank or equal to 100 they scored an A1

smoky tulip
#

Yes, and we access that score how?

#

Using the dictionary right?

#

By accessing the inputted score for that subject

void sandal
#

yeah.. the users input

smoky tulip
#

So why don’t you fill out the rest of the if statement with elifs for the other scores and show me

void sandal
smoky tulip
#

Yeah, as the scores are set, you’ll be fine to not define them

void sandal
#

definetly better than using "and"

smoky tulip
#

Yes

#

As you can always surround the value in < >

void sandal
#

ok..

#

..

#

hello?

#

.

smoky tulip
#

Hey

void sandal
#

yep..

smoky tulip
#

Have you done the other if statements

#

For the other scores?

void sandal
#

not yet done..

smoky tulip
#

👍

#

Let me see the code when you’re done

void sandal
#

i just thought you left lol

#

ok..

smoky tulip
#

Nah, I got discord open

#

Just working

void sandal
#

ok..

#

here it is

#

but i realised something

#

in the treminal is always prints english first

#

terminal*

warped onyx
#

@void sandal Check your dms đŸ«Ą

smoky tulip
#

You can always remove print(subject)

#

Also

#

What happens if someone scores 29?

void sandal
smoky tulip
#

Would they also need to get an F?

void sandal
smoky tulip
#

Did you add more lines or get rid of 40<

#

?

void sandal
smoky tulip
#

Wrong way around

#

Simply remove “40 <“

#

And keep “<= 50”

void sandal
#

oh ok

smoky tulip
#

@void sandal do you know the difference between if and elif?

void sandal
#

yep..

smoky tulip
#

So you don’t need all those if

#

Just the first one

#

The rest can be elifs

#

Technically

if Score <= 50:

Can be replaced with

else:
void sandal
#

yeah..

smoky tulip
#

Let me see the whole code

#

Should be mostly finished

void sandal
smoky tulip
#

You can replace line 29 with
else:

#

Because if you didn’t score any of the other grades

#

You’ll have to have scored an F

void sandal
#

ok..

smoky tulip
#

And that should be your code

#

You can now run it

void sandal
#

i want to rather make it tell the user that they should input a correct value

#

gimmie a sec

smoky tulip
#

If you tell me what all the input requirements are, I can help you code it up

void sandal
smoky tulip
#

Nope, it wouldn’t be there

#

You’d do it in your input

void sandal
#

oof

smoky tulip
#

So

#

Line 14,
Let’s separate it out
Let’s make a variable called score
So
Score = int(input(
))
Student_Score[subject] = Score

smoky tulip
#

Line 14 of your code

void sandal
#

theres already some code there

smoky tulip
#

You wanna make a new line underneath

void sandal
#

oh ok

smoky tulip
#

And so line 14 is
Score = int(input(
)
And line 15 is
Student_Score[subject] = score

#

This way we set our input into a variable

#

Which we can check

#

Before we add it to the dictionary

#

As you want users to have the ability to rectify their mistake

#

You don’t want to tell them they inputted the wrong number way after

smoky tulip
#

And now, you want to make a few new lines under line 14

void sandal
smoky tulip
#

So now a new line under score =

void sandal
#

yep

smoky tulip
#

while not (0 <= score <= 100):

#

This means
If the statement (0 <= score <= 100) is false, then do the following

#

And the under that you want
print(Enter a valid
)
And then a repeat of
Score = int(input(
))

void sandal
#

oh ok

#

i get it

smoky tulip
#

So as long as the user inputs the “wrong” score it’ll continue to ask for an input

void sandal
#

omg

#

youre a genius

#

how long have you been coding for?

smoky tulip
#

A few years now

#

You’ll get the hang of it soon

#

Dw

void sandal
#

ooo

#

wait so does it play in the terminal?

smoky tulip
#

Yeah

#

You just copy and paste the code over

#

Run it

void sandal
#

ive added you 😆

smoky tulip
#

And you can play as many games as you want

#

And the cards and dealer are somewhat random

rain warrenBOT
#
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.