mardi 14 avril 2020

How to count and print the inbetween range from random list

Q1. Write a program to generate 10 integer random numbers in the range [10, 50].

import random
mylist=[]

for i in range (10):
x=random.randint(10,50)
mylist.append(x)

print(mylist)

i don't know if this correct

output: [41, 40, 36, 49, 14, 12, 11, 22, 43, 25]

this the output because it's random everytime so this is where i don't know what to do.

Q2. How many of these numbers fall in the ranges 10-24.

the answer in this case should be :

output: 4

because there are 4 number in between ranges 10 to 24 on mylist output above which is 14,12,11, and 22

what code i need to write to get the [output:4]?




Aucun commentaire:

Enregistrer un commentaire