二手产品经理

二手产品经理

THIS IS RENO

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

Catbox

  1. Today I learned about the function of return in the def function. return is used to return a value after the function is executed, so that it can be called in other code.
  2. The value returned by return is stored in memory, and it needs to be assigned to a variable explicitly in order to be displayed using print.
  3. The scope of a variable declaration is different. Variables declared within a function are only effective within the function. They have no effect outside the function.
  4. Today's challenge is a character generation game. First, generate a dice to determine how many characters to generate, and then generate a 6*8 dice to determine the characters' health.

CODE#

import random

print("Character Generation Game!")


def warrior(name):
  n2 = random.randint(1, 6)
  n3 = random.randint(1, 8)
  health = n2 * n3
  return health


n1 = random.randint(1, 6)
print("This time you will generate", n1, "characters")
for i in range(n1):
  uname = input("Enter your character name: > ")
  print("Health:", warrior(uname))


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