获取用户输入数字并将其转换为单词?

时间:2016-04-13 03:31:40

标签: python string list

所以我的问题是让用户输入数小时的更短的方法,而不是我制作一个巨大的单词列表,说明用户输入1是否使其成为“一个”等。我觉得我应该使用pop但同时,我觉得我怎样才能获得用户输入以从列表中获取某个单词。

-- table definition
create table Particle_counter_HiSam ( time_utc  timestamp, ... );

-- load data
load data infile 'data.csv' 
into table Particle_counter_HiSam
fields terminated BY ',' ESCAPED BY ""
lines terminated by '\r\n'
(@var1, c2, ....)
SET time_utc = STR_TO_DATE(@var1,'%m/%d/%Y %H:%i:%S');

1 个答案:

答案 0 :(得分:1)

将输入转换为整数,然后使用它们索引已有的数组。简化示例:

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"