How to generate random questions

I have done coding. I want to know how to generate the same question randomly. from random import randint import math import csv a = float(input('Please Enter the Width of a Right Angled Triangle: ')) b = float(input('Please Enter the Height of a Right Angled Triangle: ')) def get_iteration(seed_values=None): v = {} # variable holder if seed_values is None: # generate 'random' values for a new iteration v['a'] = random.randint(1,30) v['b'] = random.randint(1,30) else: v.update(seed_values) # calculate remaining variables as needed and update v v['area'] = 0.5 * v[a] * v[b] v['c'] = math.sqrt[v[a * a] + v[b * b]] v['perimeter'] = v[a] + v[b] + v[c] return v # calculate the area Area = 0.5 * a * b # calculate the Third Side c = math.sqrt((a*a) + (b*b)) # calculate the Perimeter Perimeter = a + b + c column_names = ['Area of a right angled triangle','Other side of right angled triangle','Perimeter of right angled triangle'] values = [Area,c,Perimeter] myData = [column_names, values] myFile = open('output.csv', 'w') with myFile: writer = csv.writer(myFile) writer.writerows(myData)


4 Answers
1-4 of  4
4 Answers
  • random.randint() returns a list with integers put in a random number. What you really need is random.shuffle(). So you should make a list (I'll call it questions) because random.shuffle only works when there is a list in the parentheses. This should work because all you need to do is put your questions in the list, and let random.shuffle() do its magic:

  • Well, random.randint() returns a list with integers put in a random number. What you really need is random.shuffle(). So you should make a list (I'll call it questions) because random.shuffle only works when there is a list in the parentheses. This should work because all you need to do is put your questions in the list, and let random.shuffle() do its magic:
     

Python

Didn't get the answer.
Contact people of Talent-Python directly by clicking here