python, iterate through a list in a nested for loop

Im trying to generate from random variables for an inserting in a database but I'm always getting the same string when i try to iterate thru the widgetname list. I'm getting gadget all the 5 iterations. How do i get different string?

output Im getting

wd name: gadget
91
9
wd name: gadget
87
1
wd name: gadget
41
10
wd name: gadget
16
10
wd name: gadget
50
4 

my code:

widgetname=['sprocket', 'gizmo', 'gadget']
price=0
design_date='2010-02-10'
version=0
design_comment='design comment goes here'

count = 0
while (count < 5):
    count += 1
    for widget in widgetname:
        widget_name = widget
    for i in range(count):
        price=random.randint(1.0, 100.0)
    for j in range(count):
        version=random.randint(1.0, 10.0)

    print('wd name: '+widget_name)
    print(price)
    print(version)

Upvotes: 0

Views: 51

Answers (1)

Luke Smith
Luke Smith

Reputation: 967

You don't need all the loops, just the outer one, see the snippet below

for count in range(5):
    widget_name = random.choice(widgetname)   
    price=random.randint(1, 100)
    version=random.randint(1, 10)

Upvotes: 3

Related Questions