Skip to content
Sign upLog in
← Back to Community
how to convert java to python
Profile icon

import java.util.Scanner;
import java.util.Stack;

public class FruitBasket {
public static void main(String[] args) {
int numFruits;
String a="Apple", o="Orange", m="Mango", g="Guava";
Scanner sc= new Scanner(;
Stack basket = new Stack();

System.out.println("Catch and eat any of these fruits: ('apple' , 'orange' , 'mango' , 'guava') "); System.out.print("How many fruits would you like to catch? "); numFruits = sc.nextInt(); System.out.println("Choose a fruit to catch. Press A, O, M, or G: "); for (int i=1; i<= numFruits; i++){ System.out.println("Fruits " + i + " of " + numFruits); char select =; if(Character.toLowerCase(select)=='a'){ basket.push(a); }else if(Character.toLowerCase(select)=='o'){ basket.push(o); }else if(Character.toLowerCase(select)=='m'){ basket.push(m); }else if(Character.toLowerCase(select)=='g'){ basket.push(g); }else{ System.out.println("Fruit Not Available!"); } } System.out.println("Your Basket now has: " +basket); System.out.print("Press E to eat fruit: "); while(true){ char e =; char enter = Character.toLowerCase(e); if(enter == enter){ basket.pop(); } if(basket.isEmpty()){ System.out.println("NO MORE FRUITS!"); break; } System.out.println("Your Basket now has: " +basket); System.out.print("Press E to eat fruit: "); } }


Profile icon
Profile icon

Just check out CodingIsCool, its just a good project where you can code in Java, using Python code.

Hope you can mark this as answered lol, jk.

Profile icon

Java and Python are inherently different programming languages. With most programming languages, there's no way to just convert from one to another, you have to manually reprogram the program in the other language.

Profile icon

What do you mean? You learn python, and then reimplement the program in python.