0
Is there a prob with my answer
fruits = ["apple", "cherry", "banana", "kiwi", "lemon", "pear", "peach", "avocado"] num = int(input()) if num < 0 or num > 7: print("Wrong Number") else: print(fruits[num])
11 Answers
+ 1
What's your problem in this code?
I check your code and it gives no error then what happened?
+ 1
Thnx mate I owe you 1
0
Test case 3
Your input 12
Output
Wrong Answer
Expected Outputwrong answer
0
If you input the number less than 0 or greater than 7 then it gives you output wrong answer and you input 12 then it gives you wrong answer Because 12>7 see your if condition
0
If you print Outputwrong answer instead of Wrong Answer then:- print("Outputwrong answer") in if-block statement
0
The max number is 7
0
Please elaborate further
0
The program is supposed to output wrong Answer if the numbers chosen are out of the index
0
Imagine a vending machine that sells fruits. Each fruit has its own number, starting from 0.
Write a program for the vending machine, which will take n number as input from the customer and return the fruit with that index.If n< 0 or n>7 (the index of last fruit ), the program outputs "Wrong number".
Sample Input:
2
Sample Output:
banana
0
fruits = ["apple", "cherry", "banana", "kiwi", "lemon", "pear", "peach", "avocado"]
num = int(input())
if num > 0 and num < 7:
print(fruits[num])
else:
print("Out of index")
Like this.
0
Be careful, if u input a float like 1.5, it will return a error, the input needs to be a integer