Beginner with python, having issues with my super simple code

So I’m new to Python. I have a little experience with visual basic, and I was told that Python is actually much easier. I’m making a simple dice gambling game as my first code, but for some reason in netbeans, I have no problem with the code, but when I try to compile it, I keep getting an error. Here is the code:

import random
import sys
pmoney = 500

roll = "yes"
while roll == "yes":
    if roll == "no":
        sys.exit()
    if pmoney < 1:
        sys.exit("You ran out of money")
    pbet = input("How much do you want to bet?  ")
    if pbet > pmoney:
        pbet = input("You don't have that much, try again.  ")
    npmoney = (pmoney - pbet)
    intdroll = random.randint(1,2)
    intpnum = input("Choose a number between 1 and 2  ")
    if intpnum == intdroll:
        print("YOU WIN!")
        pmoney = (pbet * 2) + npmoney
        print("You have %d" %pmoney)
    elif intpnum != intdroll:
        print("YOU LOSE!")
        pmoney = (pmoney - pbet)
        print("You have %d" %pmoney)
    roll = raw_input("Roll again?  ")

When I try to compile it, it keeps telling me that either pbet or pmoney is a string. My brother is a software engineer and knows python pretty well. He says for some reason something is forcing my variable pbet to be a string, and he said I can force it into an integer by doing pbet = int(input()) but he said he’s not sure why I would have to do that. Any ideas would be greatly appreciated.

UPDATE:
Apparently, you have to specify integers when using the input command. Also had to change the raw_input on my last line of code as well to just input.

Hi @ldahill, welcome to the freeCodeCamp forum!

You may now realize this, but whenever you use the input built-in function to get input from the user, that function takes what the user typed in and returns it as a string value, even if they only typed in a number.

Wrapping the input function call within a call to the int built-in function will convert the string value that input returns and convert it to an integer value.

So this:

userInt = int(input('Enter a number: '))

Would give essentially the same result as performing the two calls separately:

userStr = input('Enter a number: ')
userInt = int(userStr)
1 Like