Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 混合数编程不起作用_Python - Fatal编程技术网

Python 混合数编程不起作用

Python 混合数编程不起作用,python,Python,这就是我目前编写程序的方式,因此,当一个人输入23作为分子,输入6作为分母时,会将解打印为一个混合数。但当我运行代码时,它仍然返回错误。我在什么地方出错了吗 请注意,内置功能与不同 您可能会遇到问题TypeError:format()最多接受2个参数(给定3个),这是由 def main(): num = int(input("Enter the Numerator:")) den = int(input("Enter the Denominator:")) whole_num = num /

这就是我目前编写程序的方式,因此,当一个人输入23作为分子,输入6作为分母时,会将解打印为一个混合数。但当我运行代码时,它仍然返回错误。我在什么地方出错了吗

请注意,内置功能与不同

您可能会遇到问题
TypeError:format()最多接受2个参数(给定3个)
,这是由

def main():
num = int(input("Enter the Numerator:"))
den = int(input("Enter the Denominator:"))

whole_num = num // den
fract_num = num % den

print('The mixed number is {} and {}/{}', format (whole_num, fract_num,den)) 
main ()
要修复它,请将线路更换为

print('The mixed number is {} and {}/{}', format(whole_num, fract_num,den)) 

完整的源代码,(注意代码缩进)


尝试将逗号更改为点,如下所示

def main():
    num = int(input("Enter the Numerator:"))
    den = int(input("Enter the Denominator:"))

    whole_num = num // den
    fract_num = num % den

    print('The mixed number is {} and {}/{}'.format (whole_num, fract_num, den)) 

main()

# Demo
$ python3 test.py 
Enter the Numerator:23
Enter the Denominator:6
The mixed number is 3 and 5/6

什么错误?请提供回溯。缩进错误。您在字符串和
格式之间键入了
,而不是
。如果您的代码没有运行,修复它的第一步是校对它,以确保您没有输入错误。
def main():
    num = int(input("Enter the Numerator:"))
    den = int(input("Enter the Denominator:"))

    whole_num = num // den
    fract_num = num % den

    print('The mixed number is {} and {}/{}'.format (whole_num, fract_num, den)) 

main()

# Demo
$ python3 test.py 
Enter the Numerator:23
Enter the Denominator:6
The mixed number is 3 and 5/6
print('The mixed number is {} and {}/{}'.format(whole_num, fract_num,den))