如何使def函数不显示twi

2024-04-30 06:31:04 发布

您现在位置:Python中文网/ 问答频道 /正文

当我输入'n'停止对属性进行更改时,“good choice”将重复2次,并返回charc1Stat()。我想在我输入“n”后停止。请告诉我我做错了什么,我使用的是空闲的python3.7.4

    P1=input("Enter your name player 1: ")
def main():
    stats1,choice1=charc1Stat()
    Change1(choice1,stats1)
def charc1Stat():
    totalPoints=15
    defsPoints1=0
    atckPoints1=0
    while totalPoints>0:
        charc1= input("{}, choose defs and atck to add points to ( you have a total of {} left): ".format(P1, totalPoints))
        charc1=charc1.lower()
        charc1=charc1.rstrip()
        charc1=charc1.lstrip()
        if charc1 == "defs":
            d1 = eval(input("How many points do you want to add to defs?: "))
            defsPoints1+= d1
            totalPoints= totalPoints - d1
            if totalPoints<0:
                print("Enter a number that is",totalPoints,"or less")
        elif charc1 == "atck":
            a1 = eval(input("How many points do you want to add to atck?: "))
            atckPoints1 += a1
            totalPoints= totalPoints - a1
            if totalPoints<0:
                 print("Enter a number that is",totalPoints,"or less")
        else:
            print("Enter atck or defs to add points")
    stats1={"name":P1, "defense":defsPoints1, "attack":atckPoints1}
    print("{} has {} points in defs and {} points in atck.".format(stats1["name"], stats1["defense"],stats1['attack']))
    choice1= input("Do you wish to change this? [y/n]: ")
    choice1=choice1.lower()
    choice1=choice1.rstrip()
    choice1=choice1.lstrip()
    Change1(choice1,stats1)
    return stats1,choice1
def Change1(choice1,stats1):
    if choice1[0]=='y':
        stats1,choice1=charc1Stat()
    if choice1[0]=='n'
        print("good choice")
main()``

Tags: toyouaddinputifdefspointsprint
1条回答
网友
1楼 · 发布于 2024-04-30 06:31:04

您正在调用main()函数和charc1Stat()函数中的Change1()函数。在其中任何一个中删除它,您将只收到一次消息:

P1=input("Enter your name player 1: ")
def main():
    stats1,choice1=charc1Stat()
def charc1Stat():
    totalPoints=15
    defsPoints1=0
    atckPoints1=0
    while totalPoints>0:
        charc1= input("{}, choose defs and atck to add points to ( you have a total of {} left): ".format(P1, totalPoints))
        charc1=charc1.lower()
        charc1=charc1.rstrip()
        charc1=charc1.lstrip()
        if charc1 == "defs":
            d1 = eval(input("How many points do you want to add to defs?: "))
            defsPoints1+= d1
            totalPoints= totalPoints - d1
            if totalPoints<0:
                print("Enter a number that is",totalPoints,"or less")
        elif charc1 == "atck":
            a1 = eval(input("How many points do you want to add to atck?: "))
            atckPoints1 += a1
            totalPoints= totalPoints - a1
            if totalPoints<0:
                 print("Enter a number that is",totalPoints,"or less")
        else:
            print("Enter atck or defs to add points")
    stats1={"name":P1, "defense":defsPoints1, "attack":atckPoints1}
    print("{} has {} points in defs and {} points in atck.".format(stats1["name"], stats1["defense"],stats1['attack']))
    choice1= input("Do you wish to change this? [y/n]: ")
    choice1=choice1.lower()
    choice1=choice1.rstrip()
    choice1=choice1.lstrip()
    Change1(choice1,stats1)
    return stats1,choice1

def Change1(choice1,stats1):
    if choice1[0]=='y':
        stats1,choice1=charc1Stat()
    if choice1[0]=='n':
        print("good choice")
main()

相关问题 更多 >