Python - 如何显示两个数字(字符串)之间的差异

时间:2016-05-09 09:48:01

标签: python

import random

def run_all():

    print "Welcome"
    name = get_name()
    welcome(name)
    guess = get_guess()
    print guess
    dice1 = get_dice()
    dice2 = get_dice()
    dice3 = get_dice()
    total = dice1 + dice2 + dice3
    print "Dice 1: " + str(dice1)
    print "Dice 2: " + str(dice2)
    print "Dice 3: " + str(dice3)
    print "The dices total sum is:  " + str(total)
    print "Your guess was: " + guess




def get_name():

    '''ask name'''
    return raw_input("Hi, what's your name?")

def welcome(name):

    ''' welcome'''
    print name + ", welcome!"

def get_guess():

    return raw_input("We will throw 3 dices, what do you think the total sum will be? ")

def get_dice():

    return random.randint(1,6)


run_all()

我想向玩家展示猜测与总数之间的差异,但无法弄清楚如何。

2 个答案:

答案 0 :(得分:1)

difference = abs(total - int(guess))

答案 1 :(得分:0)

difference = total - int(guess)