Python

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Programming Question

    2 answers - 1928 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Here is what I need to do:
    Create an IF branching statement that will take the
    users input from 1-10 and return the English word for
    the number. (1 is , 2 is Two, etc.) If the user
    enters a value outside of the range of 1-10, display
    an error message, and ask the user to enter a valid
    selection.
    Here is what I have so far:
    # Print the word for a number 1-10 entered by the user
    # If there is an incorrect value entered print an
    error message
    # and have them type in a correct value
    print "\nThis program prints the English word for a
    number entered between 1 and 10."
    print "\nIf an incorrect value is entered you will get
    an error message and be asked to enter a correct
    value."
    raw_input("\n\nPlease press enter to continue.")
    number = int(raw_input("Please enter a number between
    1 and 10: "))
    if number < 1:
    print "That is an incorrect number. Please try
    again."
    raw_input("Please enter a number between 1 and 10:
    ")
    if number 10:
    print "That is an incorrect number. Please try
    again."
    raw_input("Please enter a number between 1 and 10:
    ")
    elif number == 1:
    print ""
    elif number == 2:
    print "Two"
    elif number == 3:
    print "Three"
    elif number == 4:
    print "Four"
    elif number == 5:
    print "Five"
    elif number == 6:
    print "Six"
    elif number == 7:
    print "Seven"
    elif number == 8:
    print "Eight"
    elif number == 9:
    print "Nine"
    elif number == 10:
    print "Ten"
    raw_input("\n\nPress the enter key to exit.")
    How do I get it to work after an incorrect number is
    entered? I am stuck on this and would appreciate and
    help or suggestions?
    Thanks,
    Josh
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
    Tutor maillist - Tutor (AT) python (DOT) org
  • No.1 | | 569 bytes | |

    How do I get it to work after an incorrect number is
    entered? I am stuck on this and would appreciate and
    help or suggestions?

    Use exception

    try:
    int("hoge")
    except(ValueError):
    print('incorrect')

    incorrect

    elif number == 1:
    print ""
    elif number == 2:
    print "Two"
    elif

    Using table is more smart way.

    NUMBER_STRINGS = ['Zero', '', 'Two', 'Three', ]
    print NUMBER_STRINGS[number]

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.2 | | 2357 bytes | |

    cimjls wrote:
    Here is what I need to do:

    Create an IF branching statement that will take the
    users input from 1-10 and return the English word for
    the number. (1 is , 2 is Two, etc.) If the user
    enters a value outside of the range of 1-10, display
    an error message, and ask the user to enter a valid
    selection.

    Here is what I have so far:

    # Print the word for a number 1-10 entered by the user
    # If there is an incorrect value entered print an
    error message
    # and have them type in a correct value

    print "\nThis program prints the English word for a
    number entered between 1 and 10."
    print "\nIf an incorrect value is entered you will get
    an error message and be asked to enter a correct
    value."
    raw_input("\n\nPlease press enter to continue.")

    number = int(raw_input("Please enter a number between
    1 and 10: "))
    if number < 1:
    print "That is an incorrect number. Please try
    again."
    raw_input("Please enter a number between 1 and 10:
    ")
    if number 10:
    print "That is an incorrect number. Please try
    again."
    raw_input("Please enter a number between 1 and 10:
    ")
    elif number == 1:
    print ""
    elif number == 2:
    print "Two"
    elif number == 3:
    print "Three"
    elif number == 4:
    print "Four"
    elif number == 5:
    print "Five"
    elif number == 6:
    print "Six"
    elif number == 7:
    print "Seven"
    elif number == 8:
    print "Eight"
    elif number == 9:
    print "Nine"
    elif number == 10:
    print "Ten"

    raw_input("\n\nPress the enter key to exit.")

    How do I get it to work after an incorrect number is
    entered? I am stuck on this and would appreciate and
    help or suggestions?

    What happens when you try an incorrect number? You will generally get
    better help on this list when you are very specific about what happens,
    instead of saying it doesn't work.

    This looks like homework so I will just give some hints.

    There is a difference between how you use the first raw_input() call and
    the ones you make when the data is bad; can you see it?

    Do you know about while loops yet? If so, what happens if the user
    enters a bad number the second time? Can you fix it with a while loop?

    Kent

    Tutor maillist - Tutor (AT) python (DOT) org

Re: Programming Question


max 4000 letters.
Your nickname that display:
In order to stop the spam: 1 + 0 =
QUESTION ON "Python"

EMSDN.COM