0

How do I get a random element from a List ?

https://sololearn.com/coach/135/?ref=app Pls help me solve this :)

10th Dec 2021, 1:54 AM
Radhika Seelam
9 ответов
+ 9
Radhika Seelam This is a really simple code coach solutions question * python 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 The list has 8 fruits • code coach solution which is meant for you to do to help you establish your skills abilities and where you need to learn... Please show us your attempt Vasiliy this is his problem / assignment
10th Dec 2021, 3:02 AM
BroFar
BroFar - avatar
+ 5
Radhika Seelam Everything is fine, but you forgot to describe one more condition: If n<0 or n>7 (the index of last fruit ), the program outputs "Wrong number".
10th Dec 2021, 3:55 AM
Solo
Solo - avatar
+ 2
This task is available only to users of the PRO version. Describe the assignment, specify the programming language in the tag, and provide your code attempt.
10th Dec 2021, 2:41 AM
Solo
Solo - avatar
+ 2
BroFar, thanks for the assignment. ☺️ The only thing left to do is to understand why Radhika Seelam is asking to get a random item from the list? 🤔
10th Dec 2021, 3:19 AM
Solo
Solo - avatar
+ 2
Hi Vasiliy , BroFar… tried this, but something is missing fruits = ["apple", "cherry", "banana", "kiwi", "lemon", "pear", "peach", "avocado"] num = int(input()) #your code goes here if (0 <= num <= 7): print (fruits[num])
10th Dec 2021, 3:23 AM
Radhika Seelam
+ 2
Thanks so much Vasiliy 🙂 I got it
10th Dec 2021, 3:58 AM
Radhika Seelam
+ 2
By Creating A Rand Number And make {YourArrayName[Rand]}
11th Dec 2021, 1:49 PM
TeenX
TeenX - avatar
+ 1
Is this app really worth it
10th Dec 2021, 7:40 AM
Swajeet B.
Swajeet B. - avatar
+ 1
I can't access the link either because I am not a Pro
11th Dec 2021, 11:42 AM
Sonic
Sonic - avatar