我的计算机科学课程中有一项任务说明"创建一个程序,要求用户输入20到99之间的数字。然后程序必须用英文单词打印出数字。如果用户未输入介于20和99之间的值,则会显示一条错误消息,指出输入不在有效范围内。"
这是我目前在python中所拥有的。请保持愉快,我没有任何编程经验!
a=int(eval(input('Pick a number between 20 through 99:')))
b=a//10
c=a%10
if a<20 and a>99:
print('Error, enter number between 20 and 99')
elif b==2:
print('The number is Twenty',end=' ')
elif b==3:
print('The number is Thirty',end=' ')
elif b==4:
print('The number is Fourty',end=' ')
elif b==5:
print('The number is Fifty',end=' ')
elif b==6:
print('The number is Sixty',end=' ')
elif b==7:
print('The number is Seventy',end=' ')
elif b==8:
print('The number is Eighty',end=' ')
elif b==9:
print('The number is Ninety',end=' ')
if c==1:
print('One')
elif c==2:
print('Two')
elif c==3:
print('Three')
elif c==4:
print('Four')
elif c==5:
print('Five')
elif c==6:
print('Six')
elif c==7:
print('Seven')
elif c==8:
print('Eight')
else:
print('Nine')