我正在努力将你多少岁转换成几天:
print "age into days converter"
name = raw_input("What is your name: ")
age = raw_input("How old are you: ")
days_in_years = 365
age_in_days = age * days_in_years
print "You are %s days old" %age_in_days
但是,它会将您的年龄打印365次而不是乘以它。我尝试使用输入,int(, 并尝试将其转换为浮点值但它仍然无效。
答案 0 :(得分:2)
您需要将age_in_days = age * days_in_years
替换为age_in_days = int(age) * days_in_years
,以便age_in_days
是一个数字,而不是字符串。
答案 1 :(得分:1)
raw_input
将返回一个字符串,您将其乘以int
,从而导致字符串重复,而非int乘法。
将其包裹在int
来电,以获得您需要的结果
age = int(raw_input("How old are you: "))