遇到的问题
a = input('请输入a')
b = input('请输入b')
print(a,'*',b,'=',a*b)
发生异常: TypeError can't multiply sequence by non-int of type 'str'
问题:输入的数据类型为str,不能直接进行运算
解决:计算时以int将str的字符定义为整数
a = input('请输入a')
b = input('请输入b')
print(a,'*',b,'=',int(a)*int(b))
Final Project
s1 = int(input('The score for Last year'))
s2 = int(input('The score for the year'))
r = 100*(s2-s1)/s1
if r>=0:
r = r
print('The score {0} {1:.1f}%'.format('increase', r))
else:
r = -r
print('The score {0} {1:.1f}%'.format('decrease',r))
存疑
a=abc
print(a)
发生异常: NameError name 'abc' is not defined
a='abc'
print(a)
为什么赋值为字符需要引号,而数字不需要?