jeudi 8 juin 2017

Using while loop to repeat function(function that generates random numbers)

#Hi, I am having trouble when using a while loop to repeat a function.
#I am not an american student so please be understanding of my English.
#I have no clue of what is going wrong and hope I can get some help.
#I am aware that I can append the random number in the function and return it and use it to 

#I specifically have to do the following:
#1. the function should only return one random number, not a list
#2. the main program should be responsible for making a list and printing the value retrieved from the function.

def randomnumbers():

r = 0

import random

r = random.randrange(0,5)

return r    

abc = ["a", "b", "c", "d", "e"]

List = []

while randomnumbers()>=3:

List.append(abc[randomnumbers()])

for i in List:

print i




Aucun commentaire:

Enregistrer un commentaire