目前我有这个:
gpa = input("Enter your gpa: ")
gpa = int(gpa)
print("This is your current gpa:" , gpa)
如何gpa
变成小数,以便将其打印为小数?
目前我有这个:
gpa = input("Enter your gpa: ")
gpa = int(gpa)
print("This is your current gpa:" , gpa)
如何gpa
变成小数,以便将其打印为小数?
Change
gpa = input("Enter your gpa: ")
gpa = int(gpa)
to
gpa = float(input("Enter your gpa: "))
如果要转换为十进制使用:
print("This is your current gpa:" , float(gpa))
如果您想以其他格式显示:
print("This is your current gpa:" , "%.2f" % gpa)
使用 float() 函数而不是 int() 函数。
gpa = float(input("Enter your gpa: "))
print("Your current gpa is %.2f " % gpa)