这个问题在这里已经有答案了
:
如何将输入读取为数字?
(10个答案)
22小时前就关门了。
让我们以下面的代码为例:
Women = (input("What's the number of women?"))
Men = (input("What's the number of men?"))
print("Percentage of Men: " + ((Men//(Men+Women))*100) + "\n Percentage of Women: " + ((Women//(Men+Women))*100))我收到一个错误
..。
我怎么才能解决这个问题呢?
发布于 2021-03-01 14:40:09
Men = int(input("What's the percentage of men"))
Women = int(input("What's the percentage of women"))
Men = int(((Men / (Men + Women)) * 100))
Women = int(((Women / (Men + Women)) * 100))使用f字符串
print(f"Percentage of men {Men} \n Percentage of Women {Women}")发布于 2021-03-01 14:47:30
使用int()转换为number和f字符串。正常除法(/)返回一个小数,而楼层除法(//)截断小数部分并返回我们正在使用的除法运算符/ quotient.So。
women = int(input("What's the number of women?"))
men = int(input("What's the number of men?"))
print(f"Percentage of Men: {(men/(men+women))*100} \n Percentage of Women: {(women/(men+women))*100}")发布于 2021-03-01 14:49:29
你应该试试,
Women = int(input("What's the number of women?"))
Men = int(input("What's the number of men?"))
Total = Men+Women
print(f' Percentage of men: {(Men/Total)*100} ')
print(f' Percentage of Women : {(Women /Total)*100}')https://stackoverflow.com/questions/66417616
复制相似问题