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

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(System.in);
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 = sc.next().charAt(0); 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 = sc.next().charAt(0); 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: "); } }

}

Voters
Profile icon
jovrobin
Comments
hotnewtop
Profile icon
CodingElf66

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
RoBlockHead

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
Highwayman

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