我是一名试图学习Python的编程初学者。我试图完成下面的练习:Python如何将输入字符串的结果相乘
Write a program to prompt the user for hours and rate per hour to compute gross pay.
这就是我想出了:
hours = input("Enter number of hours worked\n")
rate = input("Enter pay rate per hour\n")
print(hours * rate)
当然,我收到错误:
TypeError: can't multiply sequence by non-int of type 'str'
我怎样才能知道Python认为输入的结果应该被视为整数而不是字符串?
哇!没有得到通知,我收到了一些答案。现在我看到有几种不同的方式来做到这一点。非常感谢大家。 –