+ 1
Can anyone please explain to me why my code isn't working
We are a creating a program for a vending machine and a user will be to input a number "n" which is the index of the fruit. Here's the list fruit = { apples, mangoes, bananas, cherry etc} If a user inputs 2 the machine with output bananas which is the index or number Note that I haven't written code because I have failed to reason it out
5 Answers
+ 8
Fruits = ["apple","mango","banana","cherry"]
index = int(input())
print(fruits [index])
+ 2
Philippe What you've done here is create an unordered data-type object called a 'set'. '{1, 2, 3}' (set) is different from '[1, 2 3]' (list). Sets are used when you need to find out whether a piece of data is inside a specific group. They can't be indexed (you may check out the 'sets' section here in the Python Core course).
+ 1
Please show us the code
0
import java.util.Scanner;
public class amrit{
public static void main(String[] args) {
String[] menu = {"Tea", "Espresso", "Americano", "Water", "Hot Chocolate"};
Scanner sc = new Scanner(System.in);
//your code goes here
int choice = sc.nextInt();
String a = "Invalid";
if(choice <=4) {
System.out.println(menu[2]);
}
else
{
System.out.println(a);
}
}
}
0
Am getting error