我一直在学习Python从这个YouTube视频Python教程初学者通过用Mosh编程。
在视频中(2:26:28),讲师进行了一个练习,编写一个程序,将电话号码中的数字转换为单词。我试着这样做。我目前正在Mac上使用Pycharm与Python 3.8.2。
这是我写的:
number = input('Phone: ')
number_in_words = {
'1': 'One',
'2': 'Two',
'3': 'Three',
'4': 'Four'
}
final_output = ''
for words in number:
final_output += number_in_words.get(words) + ' '
print(final_output)
这是输出:
Phone: 1234
One
One Two
One Two Three
One Two Three Four
但是,我只想要终端上的最后一行,而不是其余的。
慕森王
呼啦一阵风
有只小跳蛙
慕虎7371278
相关分类