Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a python program that generates four random between -50 and +50 using pythons random number generator import random a = 10 b =100 x

Write a python program that generates four random between -50 and +50 using pythons random number generator

import random a = 10 b =100 x = random.randint(a,b) # (1) returns an integer a <= x <= b

# modify a and b accordingly print('random integer == ', x)

# your code will require 4 statements similar to (1) above

and displays

the four integers

The maximum integer

The minimum integer

The number of even integers (if x %2 == 0 then x is even)

The number of odd integers

The number of integers greater than 0 but less than 50

The number of positive integers

The number of negative integers

The average of the smallest and largest integers

The average of all four integers

and

uses a list and the append function to add items to a list

odds = [] # list to keep track of odd evens = [] # list to keep track of evens #sample integers to use a = 20 b = 11 c = 9 d =-12 # even and odds calculations if a % 2 == 0: evens.append(a) else: odds.append(a) if b % 2 == 0: evens.append(b) else: odds.append(b) if c % 2 == 0: evens.append(c) else: odds.append(c) if d % 2 == 0: evens.append(d) else: odds.append(d) print ("evens are: " , evens) print ("odds are: " , odds) # to determine the number of integers > 10 # create 2 lists one for >10 and one for <= 10

OUTPUT:

evens are: [20, -12]

odds are: [11, 9]

The source code is attached Download, open with PyCharm and run the code

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

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions

Question

3. What may be the goal of the team?

Answered: 1 week ago

Question

Is how things are said consistent with what is said?

Answered: 1 week ago