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.
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.