Python random numebr code example
Example 1: random numbers python
import numpy
x = numpy.random.randint(100)
x = numpy.random.randint(100, size=5)
x = numpy.random.rand()
x = numpy.random.rand(5)
x = numpy.random.rand(2,3)
x = numpy.random.choice([1,5,2,3,4])
x = numpy.random.choice([1,5,2,3,4], size=(2,3))
import random
x = random.getrandbits(1)
Example 2: random.random in python
enota = input("V kateri enoti boš podal temperaturo? Vnesi 'C' ali 'F': ")
stopinje = int(input("Število stopinj: "))
if enota != "C" and enota != "F":
print("Vnesi ustrezno enoto.")
else:
if enota == "C":
odg = int(round((9 * stopinje) / 5 + 32))
nova_enota = "Fahrenheit"
elif enota == "F":
odg = int(round((stopinje - 32) * 5 / 9))
nova_enota = "Celzija"
print("Temperatura v stopinjah", nova_enota, "je", odg, "stopinj.")