How can I define a paramter in a function.

Jeffrey KANG

I'm trying to make the function dice randomly roll from 1-6. But when I try to add the different numbers from the function, it says that one and two are undefined. I'm not sure to how solve this, and I'm pretty new at coding.

import random
    def dice(name):
        name = random.randint(1,6)
        print name
    dice('one')
    dice('two')
    dicesum = float(one) + float(two)
    message = raw_input('guess the number. ')
    if dicesum == message:
        print "You guess right! You win!"
    if dicesum != message:
        print "You guess wrong! You lose!"
Reblochon Masque

You probably want one and two to represent the values returned by the dice roll:

import random


def roll_dice():
    value = random.randint(1, 6)
    print(value)
    return value


roll_one = roll_dice()
roll_two = roll_dice()
dice_sum = roll_one + roll_two
guess = int(input('guess the number. '))  # cast to int so it can be compared to dice_sum
if dice_sum == guess:
    print("You guess right! You win!")
else:
    print("You guess wrong! You lose!")

I changed the variable names and function names to what I think is a better representation of what they are and do.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I define the LAMBDA function in LISP?

From Dev

How can I define a Typescript interface for a function?

From Dev

How can I define a function in JavaScript?

From Dev

How can i use define preprocessor to define function-pointer?

From Dev

How can I define a function parameter to be a function or null?

From Dev

How can I define a function parameter to be a function or null?

From Dev

How can I define a Typescript object return value for a function?

From Dev

How can I define a return type of void for a function in a Typescript interface?

From Dev

How can I define a global function to check bounds?

From Dev

How can I define a heuristic function for water jug?

From Dev

How can I define the return type of a lodash reduce function with Typescript?

From Dev

How can I define an abstract odd function in mathematica? With respect to derivatives

From Dev

How can I define default empty input content for a function in SwiftUI?

From Dev

How can I define the return type of a lodash reduce function with Typescript?

From Dev

How can I define an abstract odd function in mathematica? With respect to derivatives

From Dev

How can i use fittype function to define a custom equation?

From Dev

How can I define a function called "import" in Python?

From Dev

How do I define a function?

From Dev

How can I define such an array?

From Dev

How I can define this constraint?

From Dev

How can I define such an array?

From Dev

Can I define an OCaml function that returns itself?

From Dev

Can I use define directive in a function scope?

From Dev

Can I use define directive in a function scope?

From Dev

How can I, in a JQuery function, define a value then call another function and use the value?

From Dev

How can I define a Javascript function that can be chained onto other Javascript libraries?

From Dev

How I can get the value of grouping column inside user define function in data.table

From Dev

How can I define a function which bind only xvalue OR prvalue but not both

From Dev

How can I define a type, that represents all binary or unary function taking ArgType as arguments and returning ReturnType?

Related Related

  1. 1

    How can I define the LAMBDA function in LISP?

  2. 2

    How can I define a Typescript interface for a function?

  3. 3

    How can I define a function in JavaScript?

  4. 4

    How can i use define preprocessor to define function-pointer?

  5. 5

    How can I define a function parameter to be a function or null?

  6. 6

    How can I define a function parameter to be a function or null?

  7. 7

    How can I define a Typescript object return value for a function?

  8. 8

    How can I define a return type of void for a function in a Typescript interface?

  9. 9

    How can I define a global function to check bounds?

  10. 10

    How can I define a heuristic function for water jug?

  11. 11

    How can I define the return type of a lodash reduce function with Typescript?

  12. 12

    How can I define an abstract odd function in mathematica? With respect to derivatives

  13. 13

    How can I define default empty input content for a function in SwiftUI?

  14. 14

    How can I define the return type of a lodash reduce function with Typescript?

  15. 15

    How can I define an abstract odd function in mathematica? With respect to derivatives

  16. 16

    How can i use fittype function to define a custom equation?

  17. 17

    How can I define a function called "import" in Python?

  18. 18

    How do I define a function?

  19. 19

    How can I define such an array?

  20. 20

    How I can define this constraint?

  21. 21

    How can I define such an array?

  22. 22

    Can I define an OCaml function that returns itself?

  23. 23

    Can I use define directive in a function scope?

  24. 24

    Can I use define directive in a function scope?

  25. 25

    How can I, in a JQuery function, define a value then call another function and use the value?

  26. 26

    How can I define a Javascript function that can be chained onto other Javascript libraries?

  27. 27

    How I can get the value of grouping column inside user define function in data.table

  28. 28

    How can I define a function which bind only xvalue OR prvalue but not both

  29. 29

    How can I define a type, that represents all binary or unary function taking ArgType as arguments and returning ReturnType?

HotTag

Archive