The following code works fine in Jupyter notebook, but shows an error in Spyder IDE. Why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

The following code works fine in Jupyter notebook, but shows an error in Spyder IDE. Why?

#Code for simulating the dice game craps import random def roll_dice(): #rolls two dice, gives the number of dots on the face facing up. die1=random.randrange(1,7) die2=random.randrange(1,7) return (die1,die2)#packs the number of dots on top face into a tuple def display_dice(dice): #prints the value of both the die die1,die2=dice print(f'Player rolled{die1}+{die2}={sum(dice)}') die_values=roll_dice() #stores the tuple returned by roll_dice() display_dice(die_values) sum_of_dice=sum(die_values) if sum_of_dice in (7,11): game_status="WON" elif sum_of_dice in(2,3,12): game_status="LOSE" else: game_status="CONTINUE" my_point=sum_of_dice print("Point is",my_point) while game_status=="CONTINUE": die_values=roll_dice() display_dice(die_values) sum_of_dice=sum(die_values) if sum_of_dice==my_point: game_status="WON" elif sum_of_dice==7: game_status="LOSE" if game_status=="WON": print("Player wins the game.") elif game_status=="LOSE": print("Player loses the game.") Error in Spyder IDE: line 15, in display_dice print(f'Player rolled {die1} + {die2} = {sum(dice)}') TypeError: 'int' object is not callable

29th Jan 2020, 8:45 PM
Punyasloka Sahoo
Punyasloka Sahoo - avatar
1 Answer
+ 2
I don't see die1 and die2 defined. that makes trouble at Lose Looks like player never lost on Jupyter notebook😉
4th Feb 2020, 5:39 PM
Oma Falk
Oma Falk - avatar