Could anyone help me please?

Here is my code!

import random
money = 100
num = random.randint(1, 2)
#Write your game of chance functions here
money = 100
num = random.randint(1, 2)
def heads_or_tails(bet, guess):
  if guess == 1 and num == 1:
  	return bet + money
  elif guess == 2 and num == 2:
    return bet + money
  elif guess == 1 and num == 2:
    return money - bet * -1
  elif guess == 2 and num ==2:
    return money - bet * -1
#Call your game of chance functions here
print(heads_or_tails(11, 2))

dice == random.randint(1, 6)

dice == random.randint(1, 6)

dice == random.randint(1, 6)

def Cho_Han(odd, even, bet, guess):
	if dice + dice == even and guess == even:
  	return money + bet
  elif dice + dice == odd and guess == odd:
 		return money + bet
  elif dice + dice == even and guess == odd:
  	return money - (bet * -1)
  elif dice + dice == odd and guess == even:    					return money - (bet * -1)
  else:
    return "Roll Again"

It seems to be returning a tab error. Could anyone please assist?

https://www.codecademy.com/practice/projects/games-of-chance

Hello :slight_smile:

Ok, so execution of this script results in this error message:

return money + bet
         ^
IndentationError: expected an indented block

This tells us a lot. Python uses indentation to mark the blocks of code, so this is a really important part of your code. Let’s take a closer look at this part:

indentation

This is how my editor renders your code, do you see the gray marks (dots and arrows) to the left of each line of code? This feature is called “whitespace rendering”, every dot is a space, every arrow is a tab. My editor renders tab as a four space characters, but this is just a matter of settings, it could render tab even as eight spaces. And this is problematic for Python, it does not really know how to treat tabs mixed with spaces.

To solve the error you have to decide to use only spaces or to only use tabs.

To not make the same mistake again you might want to think about using an external editor to write the code (this will allow you to render the whitespace in the editor, it’s really helpfull in Python programming) and use Codecademy editor only as a place to execute the code.


There is also a trivial error in this line:

elif dice + dice == odd and guess == even:    					return money - (bet * -1)

The return statement should be in the new line with one more indentation level.

1 Like

Thank you so very much! This was very helpful and my problem is solved. I am very grateful.
Please have a great day.

1 Like

Additionally, is it possible to know which editor you have used? :smile:

You’re very welcome :slight_smile:

Yeah, sure. Right now I use Visual Studio Code Insiders, which you can download here -> https://code.visualstudio.com/insiders/. But a lof of code editors support whitespace rendering natively or via plugins (for example Atom, Vim, Notepad++, IDEs from JetBrains).

2 Likes

An extremely simple, nearly fail-safe option is Thonny.

1 Like