Python Forum
append one random intergar variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
append one random intergar variable
#1
Im super new to Python, i'm still just trying to understand the syntax
I like to add a random integer variable to a list.

Online I found different examples, for appending multiple variable to a list,
for example; the extend function or using a range,
but i just want to append one random integer variable to a list
below you find my sad attempts
Wall

from random import randint

#store num
answers = []

#Random gen
num = randint(0, 9)
print(num)
    #answers[num]
    #answers.append(num)
    #answers.insert(0, num)
    #answers = [random.randint(0,9)]
    #answers.extend(randint(0, 9))

print(answers)
Reply


Messages In This Thread
append one random intergar variable - by Coastal - Dec-18-2019, 06:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Whys is asterisk and random variable necessary in these functions? rrowhe4d 5 1,700 Aug-05-2022, 07:53 AM
Last Post: Gribouillis
  trying to input a variable using random.choice python63 9 3,897 Aug-13-2020, 05:37 PM
Last Post: python63
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 2,743 Apr-22-2020, 01:01 PM
Last Post: deanhystad
  random variable function? Novice_fanatic 4 2,913 Oct-08-2019, 01:22 PM
Last Post: jefsummers
  Guidance in Creating random output for a variable. Livne_ye 1 2,610 May-04-2019, 01:18 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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