• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Python

Practice short problems on Python Random Module

  • Categories Python, Python Modules

Python Random Module Examples: 

1.What are the possible outcome(s) from the following code?  
import random
PICK=random.randint (1,3)
CITY= ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"]
for I in CITY:
    for J in range (0, PICK):
        print (I, end = "")
    print ()
(i)(ii)(iii)(iv)
DELHIDELHIDELHIDELHIDELHI
MUMBAIMUMBAIDELHIMUMBAIMUMBAIMUMBAIMUMBAI
CHENNAICHENNAIDELHIMUMBAICHENNAICHENNAIKOLKATAKOLKATAKOLKATA
KOLKATAKOLKATAKOLKATA
Ans. Option (i) and (iii) are possible
 
2.What are the possible outcome(s) from the following code? Also, specify the maximum and minimum values that can be assigned to variable SEL.
import random
SEL=random. randint (1, 3)
ANIMAL = ["DEER", "Monkey", "COW", "Kangaroo"]
for A in ANIMAL:
   for AA in range (0, SEL):
       print (A, end ="")
    print ()
(i)(ii)(iii)(iv)
DEERDEERDEERDEERDEER
MONKEYMONKEYDELHIMONKEYMONKEYMONKEYMONKEY
COWCOWDELHIMONKEYCOWCOWKANGAROOKANGAROOKANGAROO
KANGAROOKANGAROOKANGAROO
Ans. Maximum value of SEL is 3 and minimum is 1
         (iv) is the correct option.
 
3.What are the possible outcome(s) executed from the following code ?
import random
def main():
   p = "MY PROGRAM"
   i = 0
   while p[i] != "R":
       l = random.randint(0,3) + 5
       print (p[l],end ="_")
       i += 1
main()
(i)(ii)(iii)(iv)
M_M_Y_PR_G_A_GG_G_R_OO_G_G_A
Ans. (i) will not be printed
 
4.Which is the incorrect outcome executed from the following code? Also, specify the maximum and minimum values that can be assigned to variable
x = 3
N = random.randint (1, x)
for i in range (N):
    print (i, "#", i + 1)
(i)(ii)(iii)(iv)
0#10#10#10#1
1#21#21#2
2#32#3
3#4
Ans. (iii) will not be printed
           The maximum value of N is 3 and minimum is 1
 
5.Which is the incorrect outcome executed from the following code?
import random
movie_list = ['The Jungle Book', 'Finding Nemo', 'Harry Potter', 'The Incredibles', 'Frozen']

movie1 = random.choice(movie_list)
movie2 = random.choice(movie_list)
print ( movie1 ," or " ,movie2)
  1. Finding Nemo or Harry Potter
  2. Harry Potter or Toy Story
  3. Frozen or The Jungle Book
  4. Toy Story or Spider Man
Ans. (ii) and (iv) are incorrect option.
 
6.What are the possible outcome(s) executed from the following code ?
import random
color_list = ["Pink", "Red", "Sky blue", "Yellow", "Green"]
random.shuffle(color_list)
print ( color_list )
  1. [‘Sky blue’, ‘Green’, ‘Yellow’, ‘Pink’, ‘Red’]
  2. [‘Blue’, ‘Green’, ‘Pink’, ’Brown’, ‘Red’, ‘Black’]
  3. [Yellow, Sky blue, Green, Pink, Red]
  4. (‘Yellow’, ‘Red’, ‘Sky blue’, ‘Green’, ‘Pink’)
Ans. (i) , (iv) is a correct output
 
7.Which is the incorrect outcome(s) executed from the following code?
import random
list=[14, 62, 30, 57, 91]
str= ('Simply')
print ( random.choice(list),"and" , random.choice(str) )
  1. 57 and i
  2. 62 and S
  3. 20 and p
  4. 30 and M
Ans. (iii) and (iv) are incorrect options
 
8.What are the possible outcome(s) executed from the following code ? Also specify the maximum and minimum values that can be assigned to variable PICKER.
import random
N=3
PICKER = random.randint (1, N)
COLOR = ["BLUE", "PINK", "GREEN", "RED"]
for I in COLOR :
   for J in range (0, PICKER):
       print (I, end = " ")
    print ()
(i)(ii)(iii)(iv)
BLUEBLUEPINKBLUEBLUE
PINKBLUEPINKPINKGREENPINKPINK
GREENBLUEPINKGREENGREENREDGREENGREEN
REDBLUEPINKGREENREDGREENGREEN
Ans. Option (i) and (iv) are possible
          The maximum value of PICKER is 3 and minimum is 1
 
9.What are the possible outcome(s) for “Jumble String”, when following code will be executed?
import random
stringN = "SimplyCoding"
char_list = list(stringN)
random.shuffle(char_list)
stringN = ''.join(char_list)
print ( stringN )
  1. ( CmodlnpgiSyi )
  2. miSiypgoCdln
  3. ‘lCSgpimiondy’
  4. kpCyodigntS
Ans. (ii) will be printed
 
10.Which is the correct outcome executed from the following code?
import random
n1= random.randrange(1, 10, 2)
n2= random.randrange(1, 10, 3)
print (n1,"and",n2)
  1. 2 and 7
  2. 3 and 4
  3. 8 and 10
  4. 8 and 9
Ans. (ii) is correct
  • Share:
author avatar
Simply Coding

Previous post

Crack CBSE Python Questions on Tokens
April 25, 2020

Next post

Java String Patterns Programs
April 25, 2020

You may also like

Python Questions on Tokens
Crack CBSE Python Questions on Tokens
24 April, 2020
Strings
Python Problems on Strings
24 April, 2020
CBSE Python Questions on Operators
CBSE Python Questions on Operators
24 April, 2020

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now