class ATM:
def __init__(self):
self.money = 0.0
self.password = '1234'
def add_money(self, _money) -> bool:
if float(_money) > 0.0:
self.money += float(_money)
return True
return False
def pass_check(self) -> bool:
tries = 1
while input('Give me the password:\n> ') != self.password:
if tries > 2:
return False
tries+=1
print(f'#{tries}: Bad password')
return True
def withdraw(self, _money) -> bool:
if not self.pass_check():
self.close_session()
return False
if float(_money) > 0.0 and self.money - float(_money) >= 0.0:
self.money -= float(_money)
return True
return False
def get_balance(self) -> float:
return self.money
def close_session(self) -> None:
raise SystemExit(0)
# Пример использования 1
_atm = ATM()
_atm.add_money(1700)
print('Your balance is ' + str(_atm.get_balance()))
_atm.withdraw(1600)
print('Your balance is ' + str(_atm.get_balance()))
# Пример использования 2
_atm = ATM()
if _atm.add_money(1600):
print('Money successfully added!')
else:
print('Error while money adding.')
print('Your balance is ' + str(_atm.get_balance()))
if _atm.withdraw(1700):
print('Successfully withdrawn!')
else:
print('Error while money withdrawing.')
C# 8.0:
using System;
using System.Collections.Generic;
...
Random rnd = new Random();
long SumOfGreater50 = 0, Mult3 = 0, Num, n = 10;
var Negative = new List<long>();
for (; n > 0; n--)
{
Num = rnd.Next(-100, 101);
if (Num % 3 == 0)
Mult3++;
if (Num > 50)
SumOfGreater50 += Num;
if (Num < 0)
Negative.Add(Num);
}
Console.WriteLine($"Num of multipliers of 3: {Mult3}");
Console.WriteLine("Negative nums:");
foreach (long i in Negative) Console.Write($"{i} ");
Console.WriteLine($"\nSum of nums greater than 50:{SumOfGreater50}");
var a:array[1..5,1..3] of integer;
i,k,j,min,max:integer;
Begin
min=1000;
max=-1000;
for i:= 1 to 5 do
for j:= 1 to 3 do begin
a[i,j]:= random(256);
if min>a[i,j] then min:=a[i,j];
if max<a[i,j] then max:=a[i,j];
end;
writeln(min, max);
End.