Victor Cano
Victor Cano

Reputation: 29

Getting a user input digit and converting it to a word?

So my problem is a shorter way of having the user input for hours and not me making a huge list of words saying if user input 1 make it into "one" and such. I feel like I should use pop but at the same time, I feel like how will I be able to get the user input to get a certain word from the list.

def work(hourly, minuted):

    hour = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve"]

    newHour = hourly.pop[]

    if minuted == '0':
        print(hourly + " O'clock.")

    elif minuted <= '10':
        print("it is " + minuted + "  past " + hourly)

    elif minuted == '30':
        print("Half past " + hourly)

    elif minuted >= '35':
        print("quarter past " + hourly)


def main():

    hour = str(input("Please enter the hour: "))

    minute = str(input("Please enter the minutes: "))




main()

Upvotes: 0

Views: 43

Answers (1)

Marc J
Marc J

Reputation: 1433

Convert the inputs to integers, then use them to index the array you already have. Simplified example:

hours = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve"]

hour = int(input("Please enter the hour: "))

print(hours[hour-1]  + " O'clock")
# Subtract one from hour because arrays start at index 0 but hours starts at "one"

Upvotes: 1

Related Questions