Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a Python question. This is a Python question. This is a Python question. Let's add some more complexity. We still are going to

This is a Python question.

This is a Python question.

This is a Python question.

image text in transcribed

Let's add some more complexity. We still are going to continue looping. But now, on each loop, we are going to make a decision. We are going to look at a number and see if it divisible by 3. Whatever the number is, we will display it out to the machine. So, the output below has looped and displayed the results out to the screen: 7 is not divisible by 3. 9 is divisible by 3. 2 is not divisible by 3. 2 is not divisible by 3. 3 is divisible by 3. 9 is divisible by 3. Do this for 20 values (that's 20 loops), for random numbers between 0 and 30 Now, to get the random number to generate, we will import a function from the random library in Python. The function randrange () will give us a random number within a range we pass in (just like range()). So to specify the range of random numbers between 0 and 30, call randrange (30) in each loop. Just a reminder from the textbook, the syntax to pull that pre-written program is: from random import randrange You must import in the definition of the function before we can use it in your code. Until you do this, the interpreter will not see that name defined anywhere and will not execute. Also, place this line of code as the first line in your source file. In order to check whether integer x is divisible by integer y, you can use the modulo operator "%" in Python. For example, to test when x is divisible by y, you can check (x %y==0). Then use that true or false value with an if-else statement to choose which statement to print

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions