二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 4 Day 3

Record#

Catbox

  1. Today continue to learn the usage of def, parameters can be passed to the function in the parentheses of def.
  2. The parameter can be one or multiple, separated by commas between different parameters.
  3. 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)
  4. 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
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.