|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
score = int(input('请输入一个分数:'))
if 100 >= score >= 90:
print('A')
if 90 > score >= 80:
print('B')
if 80 > score >= 60:
print('C')
if 60 > score >= 0:
print('D')
if score < 0 or score > 100:
print('输入错误!')
请教论坛各位前辈,这是python 008讲代码
当我输入一个浮点型数字,例如90.5,会出现以下错误:
请输入一个分数:90.5
Traceback (most recent call last):
File "E:\software\小甲鱼Python\008了不起的分支和循环2\源代码\method1.py", line 1, in <module>
score = int(input('请输入一个分数:'))
ValueError: invalid literal for int() with base 10: '90.5'
实在不知道为什么会出现这样的错误,还望大神解答,谢谢啦
原因在第一行score = int(input('请输入一个分数:')) 其中的int()是将输入的变量类型强制转换成整型,90.5是浮点型。数据类型不对。改成score = float(input('请输入一个分数:'))就行了。
|
|