有没有办法将这段代码中的if简化为函数?我认为这很混乱


def function1 ():
print("A bible verse for however you may be feeling :)")
print("Type 'Angry', 'Confused', 'Scared', 'Sad', 'Worried' or 'Happy' and get a bible verse that matches how you're feeling!")
operation = input("How are you feeling today? : ")
#Angry
if operation in ('angry', 'Angry',) :

print("Here's a bible verse that might help you deal with feeling angry ")
print("(Proverbs 15:8)")
print("'A hot-tempered man stirs up strife, but he who is slow to anger quiets contention.'")
a = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if a == 'yes' :
print("Here's another one! ")
print("(Proverbs 15:1)")
print("'A soft answer turns away wrath, but a harsh word stirs up anger.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(Ephesians 4:31)")
print("'Let all bitterness and wrath and anger and clamor and slander be put away from you, along with all malice.'")
r = input("If you're still angry, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif a == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1()) 
#Confused
elif operation in ('confused', 'Confused') :

print("Here's a bible verse that might help you deal with feeling confused ")
print("(Psalm 143:8)")
print("'Let the morning bring me word of your unfailing love, for I have put my trust in you. Show me the way I should go, for to you I entrust my life.'")
c = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if c == 'yes' :
print("Here's another one! ")
print("(Proverbs 3:5)")
print("'Trust in the LORD with all your heart And do not lean on your own understanding.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(James 1: 2–5)")
print("'Consider it pure joy, my brothers, and sisters, whenever you face trials of many kinds because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything. If any of you lacks wisdom, you should ask God, who gives generously to all without finding fault, and it will be given to you.'")
r = input("If you're still confused, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif c == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())

#Scared
elif operation in ('scared', 'Scared') :

print("Here's a bible verse that might help you deal with feeling scared ")
print("(Hebrews 13:6)")
print("'So we can confidently say, The Lord is my helper; I will not fear; what can man do to me?'")
a = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if a == 'yes' :
print("Here's another one! ")
print("(John 14:27)")
print("'Peace I leave with you; my peace I give to you. Not as the world gives do I give to you. Let not your hearts be troubled, neither let them be afraid.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(Deuteronomy 31:6)")
print("'Be strong and courageous. Do not fear or be in dread of them, for it is the Lord your God who goes with you. He will not leave you or forsake you.'")
r = input("If you're still scared, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif a == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())
#Sad
elif operation in ('sad', 'Sad') :

print("Here's a bible verse that might help you deal with feeling sad ")
print("(Joshua 1:9)")
print("'Have I not commanded you? Be strong and courageous. Do not be frightened, and do not be dismayed, for the Lord your God is with you wherever you go.'")
a = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if a == 'yes' :
print("Here's another one! ")
print("(Romans 8:18)")
print("'For I consider that the sufferings of this present time are not worth comparing with the glory that is to be revealed to us.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(Acts 14:22)")
print("'Strengthening the souls of the disciples, encouraging them to continue in the faith, and saying that through many tribulations we must enter the kingdom of God.'")
r = input("If you're still sad, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif a == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
#Worried
elif operation in ('worried', 'Worried') :

print("Here's a bible verse that might help you deal with feeling worried ")
print("(Matthew 6:34)")
print("'Therefore do not worry about tomorrow, for tomorrow will worry about itself. Each day has enough trouble of its own.'")
c = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if c == 'yes' :
print("Here's another one! ")
print("(1 Peter 5:7)")
print("'Casting all your anxieties on him, because he cares for you.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(Philippians 4:6)")
print("'Do not be anxious about anything, but in everything by prayer and supplication with thanksgiving let your requests be made known to God.'")
r = input("If you're still worried, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif c == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())
#Happy
elif operation in ('happy', 'Happy') :

print("Here's a bible verse that might help you deal with feeling happy ")
print("(Psalm 28:7)")
print("'The Lord is my strength and shield. I trust him with all my heart. He helps me, and my heart is filled with joy. I burst out in songs of thanksgiving'")
c = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if c == 'yes' :
print("Here's another one! ")
print("(2 Corinthians 6:10)")
print("'Our hearts ache, but we always have joy. We are poor, but we give spiritual riches to others. We own nothing, and yet we have everything.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(Psalm 16:20)")
print("'Those who listen to instruction will prosper; those who trust the Lord will be joyful.'")
r = input("If you're still so happy, type 'exit', then go and praise the Lord! If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif c == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())

#Actual Program
print("A bible verse for however you may be feeling :)")
print("Type 'Angry', 'Confused', 'Scared', 'Sad', 'Worried' or 'Happy' and get a bible verse that matches how you're feeling!")
operation = input("How are you feeling today? : ")
#Angry
if operation in ('angry', 'Angry') :

print("Here's a bible verse that might help you deal with feeling angry ")
print("(Proverbs 15:8)")
print("'A hot-tempered man stirs up strife, but he who is slow to anger quiets contention.'")
a = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if a == 'yes' :
print("Here's another one! ")
print("(Proverbs 15:1)")
print("'A soft answer turns away wrath, but a harsh word stirs up anger.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : " ) 
if r == 'another' :
print("Here's the last one! ")
print("(Ephesians 4:31)")
print("'Let all bitterness and wrath and anger and clamor and slander be put away from you, along with all malice.'")
r = input("If you're still angry, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif a == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())
print(function1())
print(function1())
print(function1())
print(function1())
print(function1())
print(function1())
print(function1())
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())          
#Confused
elif operation in ('confused', 'Confused') :

print("Here's a bible verse that might help you deal with feeling confused ")
print("(Psalm 143:8)")
print("'Let the morning bring me word of your unfailing love, for I have put my trust in you. Show me the way I should go, for to you I entrust my life.'")
c = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if c == 'yes' :
print("Here's another one! ")
print("(Proverbs 3:5)")
print("'Trust in the LORD with all your heart And do not lean on your own understanding.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(James 1: 2–5)")
print("'Consider it pure joy, my brothers, and sisters, whenever you face trials of many kinds because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything. If any of you lacks wisdom, you should ask God, who gives generously to all without finding fault, and it will be given to you.'")
r = input("If you're still confused, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif c == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())

#Scared
elif operation in ('scared', 'Scared') :

print("Here's a bible verse that might help you deal with feeling scared ")
print("(Hebrews 13:6)")
print("'So we can confidently say, The Lord is my helper; I will not fear; what can man do to me?'")
a = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if a == 'yes' :
print("Here's another one! ")
print("(John 14:27)")
print("'Peace I leave with you; my peace I give to you. Not as the world gives do I give to you. Let not your hearts be troubled, neither let them be afraid.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(Deuteronomy 31:6)")
print("'Be strong and courageous. Do not fear or be in dread of them, for it is the Lord your God who goes with you. He will not leave you or forsake you.'")
r = input("If you're still scared, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif a == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())     
else :
input("There seems to be an error, click enter to try again. ")
print(function1())

#Sad
elif operation in ('sad', 'Sad') :

print("Here's a bible verse that might help you deal with feeling sad ")
print("(Joshua 1:9)")
print("'Have I not commanded you? Be strong and courageous. Do not be frightened, and do not be dismayed, for the Lord your God is with you wherever you go.'")
a = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if a == 'yes' :
print("Here's another one! ")
print("(Romans 8:18)")
print("'For I consider that the sufferings of this present time are not worth comparing with the glory that is to be revealed to us.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(Acts 14:22)")
print("'Strengthening the souls of the disciples, encouraging them to continue in the faith, and saying that through many tribulations we must enter the kingdom of God.'")
r = input("If you're still sad, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())


else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif a == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())


else :
input("There seems to be an error, click enter to try again. ")
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())

#Worried

elif operation in ('worried', 'Worried') :

print("Here's a bible verse that might help you deal with feeling worried ")
print("(Matthew 6:34)")
print("'Therefore do not worry about tomorrow, for tomorrow will worry about itself. Each day has enough trouble of its own.'")
c = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if c == 'yes' :
print("Here's another one! ")
print("(1 Peter 5:7)")
print("'Casting all your anxieties on him, because he cares for you.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(Philippians 4:6)")
print("'Do not be anxious about anything, but in everything by prayer and supplication with thanksgiving let your requests be made known to God.'")
r = input("If you're still worried, type 'exit', then spend some time in prayer. If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif c == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())

#Happy

elif operation in ('happy', 'HAppy') :

print("Here's a bible verse that might help you deal with feeling happy ")
print("(Psalm 28:7)")
print("'The Lord is my strength and shield. I trust him with all my heart. He helps me, and my heart is filled with joy. I burst out in songs of thanksgiving'")
c = (input("If you would you like another bible verse type 'yes' if not type 'no' : "))

if c == 'yes' :
print("Here's another one! ")
print("(2 Corinthians 6:10)")
print("'Our hearts ache, but we always have joy. We are poor, but we give spiritual riches to others. We own nothing, and yet we have everything.'")
r = input("If you would you like another one type 'another', if you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if r == 'another' :
print("Here's the last one! ")
print("(Psalm 16:20)")
print("'Those who listen to instruction will prosper; those who trust the Lord will be joyful.'")
r = input("If you're still so happy, type 'exit', then go and praise the Lord! If you would you like a Bible verse for another feeling, type 'again'  : " )
if r == 'exit' :
exit()
elif r == 'again' :
print(function1())
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
elif c == 'no' :
b = input("If you would you like a Bible verse for another feeling, type 'again', if you're satisfied type 'exit' : ")
if b == 'exit' :
exit()
elif b == 'again' :
print(function1())
print(function1())
print(function1())

else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())
else :
input("There seems to be an error, click enter to try again. ")
print(function1())

虽然我对宗教话题不是特别精通,但我对这个问题的看法是:

while True: 
emotions = {
'happy': 'Proverbs 15:8',
'angry': 'Proverbs 15:9'
}

bible_verses ={
'Proverbs 15:8': 'Content of Proverbs 15:8',
'Proverbs 15:9': 'Content of Proverbs 15:9'
}

intro_text = ', '.join (emotions.keys())
print('Type', intro_text, 'for a Bible verse.')

emotion = input('Emotion: ')
try:
verse = emotions[emotion.strip().lower()]
print(verse)
print(bible_verses[verse])
except KeyError:
print('Emotion bot implemented')
continue

最新更新