help to solve the problem... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

help to solve the problem...

Guys, I'm stuck... Please, help to solve the problem from Python course... Code: class BankAccount: def __init__(self, balance): self._balance = balance def __repr__(self): return "Account Balance: {}".format(self._balance) def deposit(self, amount): #your code goes here acc = BankAccount(0) acc.deposit(int(input())) print(acc) Task: You are given a BankAccount class and need to add a deposit() method to it, which adds the given amount to the private balance property. The code should declare a BankAccount object with an initial balance of 0, take a number from user input, add it to the balance using the deposit() method, and output the object. Complete the required deposit() method so the code works as expected and produces the required output.

1st Nov 2020, 1:08 PM
Doc Waxler
Doc Waxler - avatar
8 Answers
+ 3
Yep!! Now I see what was my mistake. Very grateful to you, buddy!! :)
2nd Nov 2020, 8:16 AM
Doc Waxler
Doc Waxler - avatar
+ 1
you can refer to any attribute within the class from anywhere in the class (even in methods). try making the balance equal to itself + the input in the method
1st Nov 2020, 1:13 PM
Slick
Slick - avatar
+ 1
I'm stuck here too! Can you please advise how did you go about this problem?
27th May 2021, 12:49 PM
Viraj Kumbhakarna
Viraj Kumbhakarna - avatar
28th May 2021, 7:57 AM
Doc Waxler
Doc Waxler - avatar
+ 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string accNumber = Console.ReadLine(); double balance = Convert.ToDouble(Console.ReadLine()); User user = new User(accNumber, balance); user.ShowDetails(); } } class Account { protected double Balance { get; set; } } class User : Account { public string AccNumber { get; set; } //complete the constructor public User(string accNumber, double balance) { AccNumber = accNumber; Balance = balance; } public void ShowDetails() { Console.WriteLine("Account N: " + AccNumber); Console.WriteLine("Balance: " + Balance); } } }
11th Aug 2023, 8:36 PM
Parthasarathi Panda
Parthasarathi Panda - avatar
0
Thank you, mate, for the help! I understand, that it's very easy for you, but not for me :) I've tried a lot in different ways, but it seems my skill isn't good enough for this task yet :)
1st Nov 2020, 9:27 PM
Doc Waxler
Doc Waxler - avatar
0
self._balance += amount
4th Sep 2021, 9:55 PM
Khomi TAKAYANAGI
Khomi TAKAYANAGI - avatar