Ask your own question, for FREE!
Computer Science 9 Online
Gucchi:

programming help

Gucchi:

1 attachment
Gucchi:

@ultrilliam im getting a syntax error on this line do you know whats wrong ?

Gucchi:

@vocaloid

Vocaloid:

Missing a plus sign after the first string in line 20

Gucchi:

1 attachment
Gucchi:

@vocaloid wrote:
Missing a plus sign after the first string in line 20
thank you this worked

Gucchi:

1 attachment
Gucchi:

do you know where i can add a villian name to my code?

Gucchi:

like i want the villian name: "Doctor Wicked" to show up on the output before the comma

Vocaloid:

I've just learned about classes recently, but I think it would be defined inside the Superhero class?

Gucchi:

1 attachment
Gucchi:

i have no idea why its saying this

Gucchi:

@vocaloid wrote:
I've just learned about classes recently, but I think it would be defined inside the Superhero class?
i tried that but it just says this now

Gucchi:

heres all the info:

1 attachment
Gucchi:

1 attachment
Gucchi:

and this is my story: I want to tell you about my superhero. His name is firefly and his super power is throwing fireballs and shooting lasers. As he goes against Doctor Wicked, he shouts out his motto Fire will always win! Then quickly catches up to Doctor Wicked, so he can finish him off! The villain is defeated when he is lit by burning fire and starts to faint! Firefly has now earned an additional 200 strength because of his courageous actions He now has a total of 500 strength and has saved his city from harm.

Gucchi:

i really want to know if i have written everything correctly so far

Gucchi:

i found this vid online, but its too loud i cant even understand it https://drive.google.com/file/d/1Q8Bb3f2FzcF21QKL5UxClp49INIengiK/view

SmokeyBrown:

I think the code looks good so far. Make sure you include all the parameters you need when calling the superhero method so that everything gets defined like you want it to be

Gucchi:

@smokeybrown wrote:
I think the code looks good so far. Make sure you include all the parameters you need when calling the superhero method so that everything gets defined like you want it to be
so when it says "Come up with two additional attributes and one method" , i only have to add these and put everything else in print statements?

Gucchi:

1 attachment
Gucchi:

on here

Gucchi:

also would i have to use these in my code?

1 attachment
SmokeyBrown:

Sounds like a plan. It seems like you meet the requirements. How many attributes, or parameters does your superhero method have, again?

Gucchi:

i did strength, villain, and motto so thats three attributes

Gucchi:

1 attachment
Gucchi:

did i already add a method in the code?

Gucchi:

@gucchi wrote:
i did strength, villain, and motto so thats three attributes
i still have to do villain

Gucchi:

but i cant get my villain name on the output for some reason

Gucchi:

its saying this

1 attachment
Gucchi:

1 attachment
Gucchi:

1 attachment
Gucchi:

am i doing something wrong?

SmokeyBrown:

Yeah it looks like you have a method for defining the hero and a method for adding strength so with one more method you’d fulfill the rewuirements

SmokeyBrown:

Since you included the attribute for villain in the definition method, you also need to include the attribute when you define the hero by calling the method. In the definition of the method, the villain variable can be set to the empty string. Then you’d define your hero as firehero = superhero(“Firefly”, 0, “Firefly will always win!”, “Doctor Wicked”)

Gucchi:

@smokeybrown wrote:
Yeah it looks like you have a method for defining the hero and a method for adding strength so with one more method you’d fulfill the rewuirements
wait so are the methods the same as attributes>

SmokeyBrown:

No, attributes are the same as parameters. That’s information you feed into a method to determine how it behaves. Like name is an attribute or parameter of the Superhero definition method, and you can set it as “Firefly” or any other name when you call the method

Gucchi:

i added it but whats wrong w 21 now?

1 attachment
Gucchi:

@smokeybrown wrote:
No, attributes are the same as parameters. That’s information you feed into a method to determine how it behaves. Like name is an attribute or parameter of the Superhero definition method, and you can set it as “Firefly” or any other name when you call the method
ohh ok

SmokeyBrown:

You define firehero with a villain attribute on line 18, but fireHero (with a capital H) on line 17 has no such attribute. So, when you try to find the villain attribute of fireHero on line 21 it isn’t recognized

Gucchi:

1 attachment
Gucchi:

i fixed it

SmokeyBrown:

This is actually a technique called overloading, which is when you have two or more methods in the same class with the same name but different attributes; the behavior of the method depends on which attributes you pass in that case For this exercise, we probably don’t need to use overloading, but I thought it would be interesting to share that information

Gucchi:

@smokeybrown wrote:
This is actually a technique called overloading, which is when you have two or more methods in the same class with the same name but different attributes; the behavior of the method depends on which attributes you pass in that case For this exercise, we probably don’t need to use overloading, but I thought it would be interesting to share that information
yeah we dont really need to use it

ShortlyAfterwards:

@smokeybrown wrote:
This is actually a technique called overloading, which is when you have two or more methods in the same class with the same name but different attributes; the behavior of the method depends on which attributes you pass in that case For this exercise, we probably don’t need to use overloading, but I thought it would be interesting to share that information
very interesting actually, i was having the same problem with my print statements/output for my website..

SmokeyBrown:

That’s interesting. Maybe if you comment out line 17 and leave line 18? Could be that defining fireHero without villain first gets it stuck to not include that attribute?

Gucchi:

1 attachment
Gucchi:

do i put anything for villain up there?

Gucchi:

nah it just changed to line 20 now lol

1 attachment
SmokeyBrown:

You wouldn’t, since you set the value of villain when you call the method to define the superhero

Gucchi:

@smokeybrown wrote:
You wouldn’t, since you set the value of villain when you call the method to define the superhero
ok

Gucchi:

all these other lines from the story are just printing right? i dont think that would take long: I want to tell you about my superhero. His name is firefly and his super power is throwing fireballs and shooting lasers. As he goes against Doctor Wicked, he shouts out his motto Fire will always win! Then quickly catches up to Doctor Wicked, so he can finish him off! The villain is defeated when he is lit by burning fire and starts to faint! Firefly has now earned an additional 200 strength because of his courageous actions He now has a total of 500 strength and has saved his city from harm.

Gucchi:

like the ones without methods or anything

SmokeyBrown:

Yeah I think the only other place you would need to call methods would be for adding strength points. Unless you needed to include another method I’m still not sure about the bug you’re seeing. It looks like you defined the villain attribute and included it properly… Could I see your method definition again?

Gucchi:

like the pictures?

Gucchi:

1 attachment
Gucchi:

1 attachment
Gucchi:

@smokeybrown wrote:
Yeah I think the only other place you would need to call methods would be for adding strength points. Unless you needed to include another method I’m still not sure about the bug you’re seeing. It looks like you defined the villain attribute and included it properly… Could I see your method definition again?
i really dont know either im trying everything

Gucchi:

@smokeybrown wrote:
Yeah I think the only other place you would need to call methods would be for adding strength points. Unless you needed to include another method I’m still not sure about the bug you’re seeing. It looks like you defined the villain attribute and included it properly… Could I see your method definition again?
but i thought it said one method on the pic

Gucchi:

right?

1 attachment
Gucchi:

@smokeybrown i found the issue

Gucchi:

i misspelled the word villain here bruh

1 attachment
Gucchi:

my stupidity

Gucchi:

1 attachment
Gucchi:

output perfect now, whats next

Gucchi:

what do i do here?

1 attachment
SmokeyBrown:

Nice catch! To call the method for adding points like you defined, you could call the addStrengthPts method with the “self” attribute as the variable referring to your hero and the “points” attribute as the number of points you want to add

SmokeyBrown:

Like addedPoints=200 addStrengthPts(fireHero, addedPoints) And then you can print your message saying how many points the hero gained and what their new number of points is

Gucchi:

@smokeybrown wrote:
Nice catch! To call the method for adding points like you defined, you could call the addStrengthPts method with the “self” attribute as the variable referring to your hero and the “points” attribute as the number of points you want to add
ok so if i were to add like 200 strength points to the superhero i would do something like fireHero.addStrengthPts(200)?

Gucchi:

@smokeybrown wrote:
Like addedPoints=200 addStrengthPts(fireHero, addedPoints) And then you can print your message saying how many points the hero gained and what their new number of points is
oh ok

Gucchi:

hold on lemme do it

Gucchi:

sorry for the wait, just finished eating

SmokeyBrown:

No worries, take your time :)

Gucchi:

would i add this "addedPoints=200 addStrengthPts(fireHero, addedPoints)" right after this code in the image?

1 attachment
Gucchi:

or do i write it in the def main

Gucchi:

after the def main*

SmokeyBrown:

Inside the def main, yeah. Since you're not adding any code to the method, you're just calling it in the main method

Gucchi:

ok

Gucchi:

so ill just put it anywhere in the main

SmokeyBrown:

Yup, that should work fine, as long as it's before anything that depends on the new value of fireHero.strengthPts.

Gucchi:

1 attachment
Gucchi:

1 attachment
Gucchi:

am i doing something wrong with capitalizations?

SmokeyBrown:

Ah, maybe you need to call the method from the Superhero class, like Superhero.addStrengthPts(fireHero, addedPoints)

Gucchi:

here right?

1 attachment
Gucchi:

its still saying it tho

1 attachment
SmokeyBrown:

Sorry, I meant in the main method you would call the addStrengthPts method from the Superhero class. You don't need to change the methods you already wrote, just make sure to call Superhero.addStrengthPts(...) instead of just addStrengthPts so the program knows where to look for that method (in the Superhero class)

Gucchi:

like this right?

1 attachment
Gucchi:

i put that in the main

Gucchi:

dk what this means tho

1 attachment
SmokeyBrown:

Oh, you called fireHero as an attribute of the addStrengthPts method on line 17 before you define fireHero on line 22. If you want to reference a variable, it has to be after that variable is defined. That also applies to the addedPoints attribute; you define that variable on line 19. Change the order so Superhero.addStrengthPts... appears later, and you can also get rid of line 20, addStrengthPts... since we're not calling the method that way

Gucchi:

ok so i added after now

1 attachment
Gucchi:

i put it after the line tho didnt i?

1 attachment
SmokeyBrown:

addedPoints still needs to be defined before the method which calls it as an attribute. If you put addedPoints before Superhero.addStrengthPts(...) the error message shouldn't appear. Alternatively, you can forget about the addedPoints variable and just enter the number of points as an attribute directly Superhero.addStrengthPts(fireHero, 200) but using the variable might be useful if you want to reference it later, like in your printed message

Gucchi:

@smokeybrown wrote:
addedPoints still needs to be defined before the method which calls it as an attribute. If you put addedPoints before Superhero.addStrengthPts(...) the error message shouldn't appear. Alternatively, you can forget about the addedPoints variable and just enter the number of points as an attribute directly Superhero.addStrengthPts(fireHero, 200) but using the variable might be useful if you want to reference it later, like in your printed message
oh ok, sorry it was a bit confusing for me, i got it now

Gucchi:

well i think i did everything they asked right?

1 attachment
Gucchi:

or am i missing a method or attribute?

Gucchi:

class Superhero: # Superhero class represents the facts related to a superhero. def __init__(self, name = "", strengthPts = 0, motto = " ", villain = " "): # Create a new Superhero with a name and other attributes self.name = name self.strengthPts = strengthPts self.motto = motto self.villain = villain def addStrengthPts(self, points): # Adds points to the superhero's strength. self.strengthPts = self.strengthPts + points def main(): fireHero = Superhero(“Firefly”, 0, “Firefly will always win!”, “Doctor Wicked”) print("I want to tell you about my superhero!") print(fireHero.name + "'s motto is " + fireHero.motto) print("As " + fireHero.name + " goes against " + fireHero.villain + ", he shouts out his motto ") addedPoints=200 Superhero.addStrengthPts(fireHero, addedPoints) main()

Gucchi:

my full code

SmokeyBrown:

Looks good! As far as I understand the assignment, it looks like you fulfilled the requirements

Gucchi:

it also said these actions might be used

1 attachment
Gucchi:

but i didnt need to use these in the code right?

Gucchi:

im sure i did this so yh i think thats all the requirements

1 attachment
Gucchi:

ill just add the print statements now

Gucchi:

its not really a big issue but there is no space appearing on the output between "win!" and "Then"

1 attachment
Gucchi:

1 attachment
Gucchi:

"Firefly has now earned an additional 200 strength because of his courageous actions" for this line, dont i have to write it differently, or do i just put it in a print statement?

SmokeyBrown:

@gucchi wrote:
its not really a big issue but there is no space appearing on the output between "win!" and "Then"
You can add a space at the end of the "...win!" string or at the beginning of the "Then..." string. Either "... win! " or " Then..." would make a space when they're printed together

SmokeyBrown:

@gucchi wrote:
"Firefly has now earned an additional 200 strength because of his courageous actions" for this line, dont i have to write it differently, or do i just put it in a print statement?
That should work fine. If you want to reference the value in the addedPoints variable you could say print(""Firefly has now earned an additional " + str(addedPoints) + " strength because of his courageous actions") but using the number as part of the string like you have it works as well

Gucchi:

@smokeybrown wrote:
@gucchi wrote:
its not really a big issue but there is no space appearing on the output between "win!" and "Then"
You can add a space at the end of the "...win!" string or at the beginning of the "Then..." string. Either "... win! " or " Then..." would make a space when they're printed together
thank you i solved it

SmokeyBrown:

Alright nice!

Gucchi:

i put this code but that reference thing showed up again

1 attachment
SmokeyBrown:

Line 24 also references the addedPoints variable, so it needs to be defined before then

Gucchi:

oh myb i got it

Gucchi:

perfect

1 attachment
Gucchi:

this was a hard one man

Gucchi:

but thanks so much for working on these w me bro, i honestly couldnt have done anythign without your help

Gucchi:

i have like 2 left but are you going to stay online rn?

Gucchi:

im going to answer some questions real fast

SmokeyBrown:

Sounds good. I probably can't stay online for now, but I'll try to take a look tomorrow if you still need help!

Gucchi:

@smokeybrown wrote:
Sounds good. I probably can't stay online for now, but I'll try to take a look tomorrow if you still need help!
thats fine thanks again

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!