二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 4, Day 3

Record#

Catbox

  1. Today, continue to learn the usage of def. The parentheses of def can pass parameters to the function.
  2. The parameter can be one or multiple, and different parameters are separated by commas.
  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, I just haven't learned it yet)
  4. 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

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.