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
ARBEIT MANN - avatar
11 Respuestas
+ 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 🙃]
Sakshi [Offline 🙃] - avatar
+ 1
Thnx mate I owe you 1
6th Nov 2022, 6:26 AM
ARBEIT MANN
ARBEIT MANN - avatar
0
Test case 3 Your input 12 Output Wrong Answer Expected Outputwrong answer
6th Nov 2022, 5:30 AM
ARBEIT MANN
ARBEIT MANN - avatar
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 🙃]
Sakshi [Offline 🙃] - avatar
0
If you print Outputwrong answer instead of Wrong Answer then:- print("Outputwrong answer") in if-block statement
6th Nov 2022, 5:36 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
0
The max number is 7
6th Nov 2022, 5:38 AM
ARBEIT MANN
ARBEIT MANN - avatar
0
Please elaborate further
6th Nov 2022, 5:38 AM
ARBEIT MANN
ARBEIT MANN - avatar
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
ARBEIT MANN - avatar
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
ARBEIT MANN - avatar
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 🙃]
Sakshi [Offline 🙃] - avatar
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
Magus - avatar