Record#
- Today, continue to learn the usage of def. The parentheses of def can pass parameters to the function.
- The parameter can be one or multiple, and different parameters are separated by commas.
- When calling a function, the number of parameters passed must be the same as the number defined. (I feel it doesn't have to be the same, I just haven't learned it yet)
- Write a program to roll a dice. The user defines the number of faces on the dice, and the program randomly outputs the number of points rolled.
CODE#
def roll(num):
import random
dian = random.randint(1, num)
print("The number you rolled is:", dian)
print("Dice Rolling Game")
num = int(input("How many faces does this dice have? > "))
again = ""
while True:
if again != "no":
roll(num)
again = input("Roll the dice again? yes or no?")
continue
else:
break