So, this is for my assignment and I have to create a flight booking system. One of the requirements is that it should create 3 digit passenger code that does not start with zeros (e.g. 100 is the smallest acceptable value) and I have no idea how I can do it since I am a beginner and I just started to learn Python. I have made classes for Passenger, Flight, Seating Area so far because I just started on it today. Please help. Thank you.
Asked
Active
Viewed 330 times
0
-
3Start at 100 and count up? Generate random numbers in the range 100 thru 999? It's not clear what your actual problem is. – jasonharper Oct 01 '19 at 02:31
-
You should post some amount of code for the section that you want help with, as well as what you have tried so far and where it is going wrong. – MyNameIsCaleb Oct 01 '19 at 02:32
-
Are you asking how to count from 100 to 999 or are you asking how to generate random numbers between 100 and 999? Or both? In the meanwhile, try https://stackoverflow.com/questions/2673385/how-to-generate-random-number-with-the-specific-length-in-python – smac89 Oct 01 '19 at 02:40
2 Answers
0
You may try this:
import random
numbers = range(100,1000) # 100..999
rand_num = random.choice( numbers ) # get a random number
random.shuffle( numbers ) # shuffle numbers in the random order
or do whatever else you like...

lenik
- 23,228
- 4
- 34
- 43
0
I like list comprehension for making a list of 100 to 999:
flights = [i for i in range(100, 1000)]
For the random version, there is probably a better way, but Random.randint(x, y) creates a random in, inclusive of the endpoints:
from random import Random
rand = Random()
flight = rand.randint(100,999)
Hope this helps with your homework, but do try to understand the assignment and how the code works...lest you get wrecked on the final!

pseudorandomcoder
- 39
- 1
- 3