+ 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

19th Jul 2021, 10:16 PM
Philippe Ezekiel
Philippe Ezekiel - avatar
5 Answers
+ 8
Fruits = ["apple","mango","banana","cherry"] index = int(input()) print(fruits [index])
20th Jul 2021, 3:19 AM
Pallavi Bhardwaj
Pallavi Bhardwaj - avatar
+ 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).
20th Jul 2021, 5:44 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Please show us the code
19th Jul 2021, 10:42 PM
Brain & Bones
Brain & Bones - avatar
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); } } }
26th Sep 2023, 7:25 AM
Amrit Kumar Ojha
Amrit  Kumar Ojha - avatar
0
Am getting error
26th Sep 2023, 7:25 AM
Amrit Kumar Ojha
Amrit  Kumar Ojha - avatar