2016-05-09 6 views
1
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() 

私は推測と合計の違いをプレイヤーに見せたいと思います。Python - 2つの数字(文字列)の違いを表示する方法

答えて

1
difference = abs(total - int(guess)) 
+0

あなたの答えをありがとう! – Hannah

+0

@Hannahあなたは大歓迎です。それがあなたを助けたら私の答えを正解と記してください。 :) –

0
difference = total - int(guess) 
+0

'total'が既に' int'である、あなたはそれをキャストする必要はありません。 –

+0

うん、私は気付いた、私はそれが含まれているので、キャストはしばしばバリデーションのために良いですが、私はすでに "推測"変数でそうする方法を示したと思います。 – dahui

+0

あなたの答えをありがとう! – Hannah

関連する問題