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])

6th Nov 2022, 5:23 AM
ARBEIT MANN
11 ответов
+ 1
What's your problem in this code? I check your code and it gives no error then what happened?
6th Nov 2022, 5:27 AM
Sakshi [Offline 🙃]
+ 1
Thnx mate I owe you 1
6th Nov 2022, 6:26 AM
ARBEIT MANN
0
6th Nov 2022, 5:30 AM
ARBEIT MANN
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
6th Nov 2022, 5:35 AM
Sakshi [Offline 🙃]
0
6th Nov 2022, 5:36 AM
Sakshi [Offline 🙃]
0
The max number is 7
6th Nov 2022, 5:38 AM
ARBEIT MANN
0
6th Nov 2022, 5:38 AM
ARBEIT MANN
0
The program is supposed to output wrong Answer if the numbers chosen are out of the index
6th Nov 2022, 5:39 AM
ARBEIT MANN
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
6th Nov 2022, 5:40 AM
ARBEIT MANN
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.
6th Nov 2022, 6:20 AM
Sakshi [Offline 🙃]
0
Be careful, if u input a float like 1.5, it will return a error, the input needs to be a integer
7th Nov 2022, 3:48 PM
Magus