Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS PROGRAM IS FOR PYTHON THIS PROGRAM IS FOR PYTHON Let's add some more complexity. We still are going to continue looping. But now, on

THIS PROGRAM IS FOR PYTHON

THIS PROGRAM IS FOR PYTHON

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions