简单调试

2024-09-29 23:18:04 发布

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

我是一名六年级的学生,这里的一些编码有问题。
我试图编写一个允许用户(我的朋友)在联系人之间切换的代码,但我一直收到一个错误

例如,我会键入ezramason(即ezra mason,但不带空格),然后应该让此人返回联系人并选择另一个人
然而,大多数情况下,它只是一团糟并停止

另外,你能不能帮我添加一些很酷的效果,在句子中一个接一个地添加个性,我是个初学者,所以我不知道怎么做

des2 = input("Would you like to be redirected to main page or contacts?") if des2 == "contacts": print() print ("| Ezra Mason | Nik Malikov | Hanna Donnelly") #contact options des3 = input("Who would you like to contact?") if des3 == "ezra mason": print ("") print ("") print("") print (" Personel is not active ") print ("") print ("") print ("") print ("| Ezra Mason | Nik Malikov | Hanna Donnelly") des3 = input("Who would you like to contact?") if des3 == "nik malikov": print ("|Nik Malikov| Date:08/09/75| Location:Heimdall|") print ("") print ("") print ("0:34 ───|────── 0:53") print ("|◁ II ▷|") print ("") print ("") print ("'I'm bacc lmao", login, "I just sent you the URL for the surveillance footage in your Karezna email. It took me forever to find it so you better thank me later") print ("") print ("") print (" Redirecting to Contacts") print () print() print () print ("| Ezra Mason | Nik Malikov | Hanna Donnelly") des3 = input("Who would you like to contact?") if des3 == "hanna donnelly": print() print() print() print ("|Hanna Donnelly| Date:08/07/75| Location:Heimdall|") print ("") print ("") print ("1:42 ───|────── 3:57") print ("|◁ II ▷|") print("") print("") print("") print("", login, "It's not just me, no one trusts nik. Listen he's weird like really weird, but it's your choice if you want to invite him to the party. Your my bestfriend, you understand I'm helping you right? (", login,": I know, don't worry, I'll keep an eye on him in the party. Hannah Donnely: Listen, I love you and all, but dad needs me to help get his telegram out of the toilet, again. Don't forget, I'm picking you up at 8 Pm for the party and bring 70 iSH.") print() print () print () print ("| Ezra Mason | Nik Malikov | Hanna Donnelly") des3 = input("Who would you like to contact?")

Tags: thetoyouinputifcontactlikeprint
1条回答
网友
1楼 · 发布于 2024-09-29 23:18:04

你不应该多次问这个名字。只请求一次,然后对照所有不同的名称检查输入

如果要重复执行,请使用while循环

des2 = input("Would you like to be redirected to main page or contacts?") 
if des2 == "contacts": 
    print() 

    while True:
        print ("| Ezra Mason | Nik Malikov | Hanna Donnelly") 
        #contact options 

        des3 = input("Who would you like to contact (or 'done')?")
        if des3 == "ezra mason": 
            print ("") 
            print ("") 
            print("") 
            print (" Personel is not active ") 
            print ("") 
            print ("") 
            print ("") 

        elif des3 == "nik malikov": 
            print ("|Nik Malikov| Date:08/09/75| Location:Heimdall|") 
            print ("") 
            print ("") 
            print ("0:34 ───|────── 0:53") 
            print ("|◁    II       ▷|")  
            print ("") 
            print ("") 
            print ("'I'm bacc lmao", login, "I just sent you the URL for the surveillance footage in your Karezna email. It took me forever to find it so you better thank me later") 
            print ("") 
            print ("") 
            print (" Redirecting to Contacts") 
            print () 
            print() 
            print () 

        elif des3 == "hanna donnelly": 
            print() 
            print() 
            print() 
            print ("|Hanna Donnelly| Date:08/07/75| Location:Heimdall|") 
            print ("") 
            print ("") 
            print ("1:42 ───|────── 3:57") 
            print ("|◁    II       ▷|") 
            print("") 
            print("") 
            print("") 
            print("", login, "It's not just me, no one trusts nik. Listen he's weird like really weird, but it's your choice if you want to invite him to the party. Your my bestfriend, you understand I'm helping you right? (", login,": I know, don't worry, I'll keep an eye on him in the party. Hannah Donnely: Listen, I love you and all, but dad needs me to help get his telegram out of the toilet, again. Don't forget, I'm picking you up at 8 Pm for the party and bring 70 iSH.")
            print()
            print ()
            print ()

        elif des3 == "done":
            break

相关问题 更多 >

    热门问题