how do i make x a random number from 1 to 100? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

how do i make x a random number from 1 to 100?

x= y=x*8 z=y*3 a=(z+y)/2 print(a) if 50<a<500: print("oy mate, thats a large number.") else: if 500<=a<1000: print("matey, ye be finding some large integers.") else: if 1000<=a: print("that number be a kraken") if a<=50: print("oy matey, thats a wee lil feller") as you can see i was messing around (this is like a practice code for me) and i have it set to give certain messages for certain values to the math equation. how do i make x random to not have to change it manually every time? i tried doing x= import random: blah blah and it keeps saying invalid syntax on the import bit. please help me out edit: i figured it out. i did import random number=random.randint(1,100) x=number print(x) i know the x=number isnt needed and print could be number but i prefer individual variables :)

8th Sep 2016, 2:37 AM
azdbacks 17
azdbacks 17 - avatar
5 Answers
+ 5
To make what Bogdan said more simple import random value = random.randint(1, 100) print(value)
11th Sep 2016, 8:42 PM
Oscar
Oscar - avatar
+ 3
first say: import random, that will import module for random numbers, then say: x = random.randint(1,1000) and it will print random number between one and 1000, also, you can use any number you like just insert it in ()
8th Sep 2016, 6:42 PM
Bogdan Caleta
Bogdan Caleta - avatar
+ 1
#Learnt this yesterday. 4 lines of code though. I'm practicing. from random import choice as a value=list (range(1,100)) realvalue=a (value) print (realvalue)
12th Jul 2018, 5:11 PM
realcosmos
realcosmos - avatar
0
ok
20th Sep 2016, 7:17 PM
Roman Asanov
Roman Asanov - avatar
0
Ок
20th Sep 2016, 7:50 PM
Roman Asanov
Roman Asanov - avatar