Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类型错误:Can';t转换为';int';对象到str隐式|自定义游戏| Python_Python_Loops_Python 3.x_Integer_Type Conversion - Fatal编程技术网

类型错误:Can';t转换为';int';对象到str隐式|自定义游戏| Python

类型错误:Can';t转换为';int';对象到str隐式|自定义游戏| Python,python,loops,python-3.x,integer,type-conversion,Python,Loops,Python 3.x,Integer,Type Conversion,嘿,伙计们,这是我正在做的一个小游戏。据我所知,错误在于,当你第一次进入银行提取现款以支付其罚款时,但下一次它读到onhand时,它会推我|回溯(最近一次调用):文件“”,第1行,在TypeError中:无法隐式地将'int'对象转换为str |不管怎样,一旦你使用onhand=int(onhand)+int(amount2)时,它看起来就是这样的它在某些方面改变了字符串,为什么不能以打印方式显示(“~On-Hand:“+onhand”)谢谢大家 开始 玩家创建 第一菜单第一菜单 count=0

嘿,伙计们,这是我正在做的一个小游戏。据我所知,错误在于,当你第一次进入银行提取现款以支付其罚款时,但下一次它读到onhand时,它会推我|回溯(最近一次调用):文件“”,第1行,在TypeError中:无法隐式地将'int'对象转换为str |不管怎样,一旦你使用onhand=int(onhand)+int(amount2)时,它看起来就是这样的它在某些方面改变了字符串,为什么不能以打印方式显示(“~On-Hand:“+onhand”)谢谢大家

开始 玩家创建 第一菜单第一菜单
count=0
当计数小于1000时:
打印(“”)
打印(“”)
打印(“”)
打印('你走进你的房间做什么?')
打印(“~~~~~~~~~~~~~”+energy+'.~~~名称:~~~~~'+Name)
打印('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
时间。睡眠(1)
打印(~1 |支票银行账户~)
时间。睡眠(1)
打印(~2 |去蒂凡尼餐厅吃饭~)
时间。睡眠(1)
打印(~3 |游览尤拉西奇公园~)
时间。睡眠(1)
打印(“~4|工作+7~”)
时间。睡眠(1)
打印(~5 |睡眠+10能量~)
打印(“~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~”)
choice1=输入(“输入选项:”)
第一菜单第一菜单 银行
如果int(choice1)==1:
打印(“”)
打印(“~~~~~~~~~~~~~”+energy+'.~~~名称:~~~~~'+Name)
打印(“~First Dodo National Bank~”)
时间。睡眠(1)
打印(“~Name:+Name”)
时间。睡眠(1)
打印(“~Age:+Age”)
时间。睡眠(1)
打印(“~Bank#:12342215”)
时间。睡眠(1)
打印(“~余额:+货币)
时间。睡眠(1)
打印(“~现有:+现有)
时间。睡眠(3)
打印('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
打印(“”)
打印('1 |存款')
打印('2 |撤回')
打印('3 |离开')
choice2=输入(“输入选项:”)
打印('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
如果int(选项2)==1:
amount1=输入('输入金额:')
如果int(数量1)>int(现有):
打印(“你手头没有那么多钱。”)
elif int(金额1)int(货币):
打印('你在银行里没有那笔钱')
elif int(数量2)int(现有):
打印(“你手头没有那么多钱。”)
elif int(金额1)int(货币):
打印('你在银行里没有那笔钱')

elif int(amount2)如果不能隐式执行,则显式执行

print ("~ On Hand: " + str(onhand))

您给打印的参数,
“~On Hand:“+onhand
是字符串串联。这两个部分必须是一个字符串,才能将两者连接在一起。一旦你完成了
onhand=int(onhand)+int(amount2)
那么
onhand
就是一个整数,而不是字符串

有两种主要方法可以进行字符串格式化。我发现最简单的方法是
.format()
方法,它将字符串中的
{}
替换为
format
的参数:

"~ On Hand: {}".format(onhand)
您还可以使用,例如:

" ~ On Hand: %s" % onhand
顺便提一下,这些:

int(money)
int(onhand)
因为他们自己在线,所以不要做任何有用的事情

import time
energy = "10"
int(energy)
money = "500"
onhand = "10"
int(money)
int(onhand)
#PLAYER CREATION
print ("Create Your Player!")
print (".......................")
name = input ("What's Your Name:") 
print ('Okay Gotcha ' + name)
time.sleep (2)
print ('')
age = input ("What's Your Age Sir?:")
print ("Okay Gotcha you're " + age)
time.sleep (2)
print ('')      
hometown = input ("Where Are You From?:")
print ("It's Nice Over In " + hometown + ' huh')
time.sleep (2)
print ('')
print ("Well im done here. Have a nice trip!")
time.sleep (5)
print ('')
#PLAYER CREATION



#INTRO
print ('You Just Flew In From Your Home Town Of ' + hometown + " You're Excited About Your New Job In Jurassic Park")
time.sleep (4)
print ('')
print ('Bob: Well ' + name + ' Welcome To JURASSIC PARK!')
time.sleep (2)
print ('')
print ("Bob: So you're the new guy huh? Well I think you'll like it here.")
time.sleep (4)
print ('')
print ("Bob: Anyways your job is at the souvenir stand ")
time.sleep (3)
print ('')
print ("Bob: You can also get promoted so you won't be stuck selling rubber dinos forever don't worry")
time.sleep (3)
print (" ")
print ("Bob: ah here we are! *You arrive at a hotel inn called ~Le Dodo Pin~* Bob: Well good luck and if you")
print (" ")
time.sleep (2)
print ("get lost there are maps everywhere, if you're looking for a place to eat Tiffanys is one of the best")
print (" ")
time.sleep (2)
print ("food joints around here, anyways I have to go good luck! Don't let the dinos bite haha.")
time.sleep (4)
#INTRO

# 1ST MENU MENU MENU MENU MENU 1ST
count = 0
while count < 1000:
    print (' ')
    print (' ')
    print (' ')
    print ('You walk into your room what do you do?')
    print ("~~~~~~~~~energy~~| "+ energy + '|~~Name:~~|' + name)
    print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
    time.sleep (1)
    print ("~ 1  |  Check Bank Account     ~")
    time.sleep (1)
    print ("~ 2  |  Go Eat At Tiffany's    ~")
    time.sleep (1)
    print ("~ 3  |  Tour Jurrasic Park     ~")
    time.sleep (1)
    print ("~ 4  |  Work      +$7          ~")
    time.sleep (1)
    print ("~ 5  |  Sleep     +10 energy   ~") 
    print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    choice1 = input ("Enter Choice:")
# 1ST MENU MENU MENU MENU MENU 1ST


#BANK BANK BANK
    if int(choice1) == 1:
        print (' ')
        print ("~~~~~~~~~energy~~| "+ energy + '|~~Name:~~|' + name)
        print ("~ First Dodo National Bank ~")
        time.sleep (1)
        print ("~ Name: " + name)
        time.sleep (1)
        print ("~ Age: " + age)
        time.sleep (1)
        print ("~ Bank #: 12342215")
        time.sleep (1)
        print ("~ Balance: " + money)
        time.sleep (1)
        print ("~ On Hand: " + onhand)
        time.sleep (3)
        print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
        print (' ')
        print ('1 | Deposit')
        print ('2 | Withdraw')
        print ('3 | Leave')
        choice2 = input ("Enter Choice:")
        print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
        if int(choice2) == 1:
            amount1 = input ('Enter Amount:')
            if int(amount1) > int(onhand):
                print ('You Dont Have That Much Money On Hand.') 
            elif int(amount1) <= int(onhand):
                money =  int(money) + int(amount1)
                count += 1
        elif int(choice2) == 2:
             amount2 = input ('Enter Amount:')
             if int(amount2) > int(money):
                 print ('You Dont Have That Money In The Bank.') 
             elif int(amount2) <= int(money):
                onhand = int(onhand) + int(amount2)
                count += 1
        elif int(choice2) == 3:
            count += 1
#BANK BANK BANK
print ("~ On Hand: " + str(onhand))
"~ On Hand: {}".format(onhand)
" ~ On Hand: %s" % onhand
int(money)
int(onhand)