Trap
Trap

Reputation: 65

Python: Skip user input and call later on

I'm fairly new to Python and am currently just learning by making some scripts to use at work. Real simple, just takes user input and stores it in a string to be called later on. The questions are yes/no answers but I wish for the user to have the option to skip and for the question to be asked again at the end, how would I do this?

Currently this is what I've got:

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()

then at the end of the script after all the questions have been asked I have this:

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.'

I understand this is very messy and I'm just looking for guidance/help.

Regards, Trap.

Upvotes: 0

Views: 3941

Answers (2)

emil
emil

Reputation: 1

# 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`

Upvotes: 0

TerryA
TerryA

Reputation: 60024

Since you're rather new to Python I'll give you some tips:

  1. Store all the questions which receive "skip" as a response into a list.
  2. At the end of all your questions, iterate through (hint: "for" loop) all the questions which the user skipped and asked them again.

Upvotes: 2

Related Questions