Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sage program question
#2
First some house cleaning.
You don't need line 4. Lines 6 & 7 can be written as
questionmark = "?"
haddaway = "What is love?"
Quote:How can I let python check for the intended input in a practical manner?

Usually you can do this with the "try/except" statement, for example:

answer = ["yes", "no"]

while True:
    try:
        response = input("Enter your response: ")
        if response in answer:
            print("Correct response")
            break
        else:
            print("Wrong response, try again")
            continue
    except ValueError as err:
        print("There was an error {}".format(err))

print("Done")
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Messages In This Thread
Sage program question - by Doesnotcompute - Oct-21-2016, 09:45 AM
RE: Sage program question - by sparkz_alot - Oct-21-2016, 03:15 PM
RE: Sage program question - by nilamo - Oct-24-2016, 05:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic Coding Question: Exit Program Command? RockBlok 3 684 Nov-19-2023, 06:31 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020