Write Python code that would generate random integers in the following ranges (e
ID: 3686697 • Letter: W
Question
Write Python code that would generate random integers in the following ranges (each of which is inclusive of the end-points): a. 0 – 100 b. 1 – 100 c. 50 – 60 d. –10 – 10 e. –16 – 21
Using the random module, write a Python program that generates and prints 30 random phone numbers of the form XXX-XXX-XXXX where the first group of three digits may not start with a 0 or a 1, the middle three digits must form an even number between 900 and 998 (inclusive), and the last group of four digits must be between 0000 and 9999 (inclusive). Your program may place no other restrictions on any of the groups of numbers. Exactly 10 digits and the two dashes must be printed.
Write a Python program that rolls a pair of 6-sided dice until they are both ones. After each roll, including the final, double-1s roll, print the pair of dice that were rolled. Keep track of how many rolls are needed until we hit snake eyes and print that count after the final roll.
Explanation / Answer
import random
print ('randrange(0,100) :', random.randrange(0,100))
print ('randrange(0,100) :', random.randrange(1,100))
print ('randrange(0,100) :', random.randrange(50,60))
print ('randrange(0,100) :', random.randrange(-10,10))
print ('randrange(0,100) :', random.randrange(-16,21))
----------------------------------------------------------
import random
f = random.randrange(200,999)
s = random.randrange(900,998,2)
t = random.randrange(0000,9999)
print(f,"-",s,"-",t)
-------------------------------------------------------
import random
c = 0;
while(True):
c = c+1;
f = random.randrange(0,6)
s = random.randrange(0,6)
if(f==s) :
print("Both are ones")
print("Total rolls : ",c)
break;
else:
print("Roll ",c," : ",f,",",s)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.