random.randint()
function takes in two
arguments. The first is the minimum value, and the second is the
maximum value. If you put them in correctly, you get a random number:
import random number = random.randint(1, 10) print(number) # random number between 1 and 10
import random number = random.randint(10, 1) print(number) # Traceback (most recent call last): # File "main.py", line 2, in <module> # number = random.randint(10, 1) # File "random.py", line 370, in randint # return self.randrange(a, b+1) # File "random.py", line 353, in randrange # raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width)) # ValueError: empty range for randrange() (10, 2, -8)
random.randint()
function works fine with integers, but if
you try to use floats or strings, you will get an error:
import random number = random.randint(1.5, 10.6) print(number) # Traceback (most recent call last): # File "main.py", line 2, in <module> # number = random.randint(1.5, 10.6) # File "random.py", line 370, in randint # return self.randrange(a, b+1) # File "random.py", line 309, in randrange # raise ValueError("non-integer arg 1 for randrange()") # ValueError: non-integer arg 1 for randrange()
# name must be a string def say_hello(name): print("Hello " + name)
Your code
def add_numbers(a, b): print(a + b)
Your code
def is_less_than(a, b): print(a - b < 0)
Your code
def describe_person(name, age): future_age = str(age + 4) print("In four years, " + name + " will be " + future_age + " years old")
Your code
def get_time_period(hour): if hour < 12: print("AM") else: print("PM")
Your code