random in py code example
Example 1: how to use random in python
import random
print(random.randint(3, 7)) #Prints a random number between 3 and 7
array = [cars, bananas, jet]
print(random.choice(array)) #Prints one of the values in the array at random
Example 2: random number pythob
import random
random.randint(a,b)
Example 3: how to import random in python
import random
Example 4: random in python
print(random.randint(1, 100))
print(random.random())
Example 5: 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.")