Discuss / Python / 两数相乘

两数相乘

Topic source

DemacL

#1 Created at ... [Delete] [Delete and Lock User]
a1 =  input('请输入第一个数:')
print('第一个数:' + a1)
a2 =  input('请输入第二个数:')
print('第二个数:' + a2)
print(a1 ,'*' , a2 , '=',  (float(a1) * float(a2)))

DemacL

#2 Created at ... [Delete] [Delete and Lock User]

请问变量不需要声明类型? 计算的时候又需要强制转换才不报错 不是太明白

bryant_byr

#3 Created at ... [Delete] [Delete and Lock User]

通过input()函数输入的a1,a2是str类型的

怎么才能使得A1和a2的值相乘呢?


  • 1

Reply