преобразовать код Java в Python Online
package com;
public class ToyDemo {
public static void main(String[] args) {
Toy one=new Toy("Banana","fruit",100,10.5);
Toy two=new Toy("Orange","fruit",300,30);
Toy three=new Toy("Lion","animal",50,5);
Toy four=new Toy("Tiger","animal",70,7);
System.out.println(getLeastPriceToy(one, two, three, four,"fruit"));
System.out.println(getLeastPriceToy(one, two, three, four,"animal"));
}
public static String getLeastPriceToy(Toy one, Toy two, Toy three, Toy four,
String category) {
Toy ansToy = one;
if(two.getCategory().equals(category) &&
(two.getPrice()*two.getDiscount())<(ansToy.getPrice()*ansToy.getDiscount())){
ansToy =two;
}
if(three.getCategory().equals(category) &&
(three.getPrice()*three.getDiscount())<(ansToy.getPrice()*ansToy.getDiscount())){
ansToy =three;
}
if(four.getCategory().equals(category) &&
(four.getPrice()*four.getDiscount())<(ansToy.getPrice()*ansToy.getDiscount())){
ansToy =four;
}
return ansToy.getName();
}
}
Careful Cat