Using the library module random there is a routine of random.randint(n,m) that generates a random integer in the range of n to m. The first line should be import random. Then you can access the routine of random.randint(n,m) Write a program that generates five random integers in the range of 1 to 3. Then take these five values and create a set. Then print out the set and it’s length. It seems as the output set always is {1,2,3} and of length three even though 5 numbers were used to form the string. It never is longer than 3, why is that? On rare occasion it will have a length of 2 and even more rare a length of 1. Can you think of a reason why? What changes in the output if random.randint(n,m) is now configured to generate random numbers in the range of 1 to 10?
Using the library module random there is a routine of random.randint(n,m) that generates a random integer in the range of n to m. The first line should be import random. Then you can access the routine of random.randint(n,m) Write a program that generates five random integers in the range of 1 to 3. Then take these five values and create a set. Then print out the set and it’s length. It seems as the output set always is {1,2,3} and of length three even though 5 numbers were used to form the string. It never is longer than 3, why is that? On rare occasion it will have a length of 2 and even more rare a length of 1. Can you think of a reason why? What changes in the output if random.randint(n,m) is now configured to generate random numbers in the range of 1 to 10?
Step by step
Solved in 2 steps