Record#
- Today continue to learn the usage of def, parameters can be passed to the function in the parentheses of def.
- The parameter can be one or multiple, separated by commas between different parameters.
- 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, just haven't learned it yet)
- Write a dice rolling program. 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
dice = random.randint(1, num)
print("The number you rolled is:", dice)
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