Python Forum
random numbers and stats
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random numbers and stats
#1
2. Part 2 - Statistics on Random Numbers - 5pts
Generate 500 random numbers on the interval 1 to 65536. Determine the fraction of these numbers which are greater than or equal to 512 and less than or equal to 2048. Display the result. Stop execution by means of an input statement which asks the user if they want to execute the next part of the assignment, prompt for a ’Y’ to continue or ’N’ to terminate execution.

import random
for x in range(500):
print random.randint(1,65536)
I need help with the second part
Reply
#2
Generate 500 random numbers on the interval 1 to 65536. Determine the fraction of these numbers which are greater than or equal to 512 and less than or equal to 2048. Display the result. Stop execution by means of an input statement which asks the user if they want to execute the next part of the assignment, prompt for a ’Y’ to continue or ’N’ to terminate execution.

import random
for x in range(500):
	print random.randint(1,65536)
[hr]
[python]
import random
for x in range(500):
	print random.randint(1,65536)
Reply
#3
Your code repeats itself and you haven't asked any questions?
Seems like the next step is a test condition like:
if  512 < x and < 2048 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,369 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 2,935 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Scaling random numbers within specific range schniefen 4 3,135 Oct-28-2019, 11:22 AM
Last Post: jefsummers
  How to Generate and Print An Array with Random Numbers in Python in the johnnynitro99293 14 9,451 Sep-20-2019, 11:56 AM
Last Post: ichabod801
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,054 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE
  NEED HELP Pseudo-Random Numbers Kongurinn 9 5,348 Oct-23-2017, 04:17 AM
Last Post: Skaperen
  List with Random Numbers AnjyilLee 5 9,259 Oct-14-2017, 09:22 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020