我对Python很陌生,目前我正在通过制作一些在工作中使用的脚本来学习。真正的简单,只需要用户输入并将其存储在稍后要调用的字符串中。问题是肯定/否答案,但我希望用户可以选择跳过,并在最后再次询问问题,我该怎么做?
目前这就是我所拥有的:
import sys
yes = ('yes', 'y')
no = ('no', 'n')
skip = ('skip', 's')
power = str(raw_input("Does the site have power? (Yes/No): "))
if power.lower() in yes:
pass
elif power.lower() in no:
pass
elif power.lower() in skip:
pass
else:
print ''
print '%s is an invlaid input! Please answer with Yes or No' % power
print ''
exit()
然后在脚本结束后,在询问了所有问题之后我得到了这个:
if power.lower() in skip:
power = str(raw_input("Does the site have power? (Yes/No): "))
if power.lower() in yes:
pass
elif power.lower() in no:
pass
else:
print ''
print '%s is an invlaid input! Please answer with Yes or No' % power
print ''
exit()
else:
pass
if power.lower == 'yes':
print 'Site has power'
else:
print 'Site doesnt have power, NFF.'
我知道这非常混乱,我只是在寻求指导/帮助。
此致 陷阱。
答案 0 :(得分:2)
由于您不熟悉Python,我会给您一些提示:
答案 1 :(得分:0)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
message=("is this correct")
Print=(message)
#store input
answer = input("yes/no:")
if answer == "yes": print("thank you")
if answer == "no": print("hmm, are you sure?")
#store input
answer = input("yes/no:")
if answer == "yes" : print("please call my suppot hotline: +47 476 58 266")
if answer == "no" : print("ok goodbye:)")
if someone had a solution for line 7 when answerd yes skiped to the end desplaing ok `goodbye:) thank you`