Python Forum
Everything works except for one line of code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Everything works except for one line of code
#3
  • def sum_integers(): should be indented into the class and should have self as a first parameter.
  • sum = x + y x &y need self. in front of them

class SumTheIntegers:
    def __init__(self):
        self.x = 10
        self.y = 13
 
    def sum_integers(self):
        sum = self.x + self.y
        return sum
     
def main():
    sum_integers = SumTheIntegers()
     
    print("The value of x is", sum_integers.x)
    print("The value of y is", sum_integers.y)
    print()
    print("The sum is", sum_integers.sum_integers())
     
main()
Reply


Messages In This Thread
RE: Everything works except for one line of code - by Yoriz - Sep-06-2019, 05:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing the code line number arbiel 2 161 Yesterday, 07:37 PM
Last Post: arbiel
  Unable to understand the meaning of the line of code. jahuja73 0 426 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 1,376 Nov-15-2023, 06:56 PM
Last Post: jst
  Code works but doesn't give the right results colin_dent 2 829 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Code used to work 100%, now sometimes works! muzicman0 5 1,621 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  Pandas - error when running Pycharm, but works on cmd line zxcv101 1 1,436 Jun-18-2022, 01:09 PM
Last Post: snippsat
  Pyspark - my code works but I want to make it better Kevin 1 1,896 Dec-01-2021, 05:04 AM
Last Post: Kevin
Question email code works in 2.7 but not in 3 micksulley 3 2,706 Nov-04-2021, 09:44 PM
Last Post: micksulley
  My simple code don't works !! Nabi666 1 1,675 Sep-06-2021, 12:10 PM
Last Post: jefsummers
  how long can a line of code be? Skaperen 2 2,297 Jun-09-2021, 06:31 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020