首页 > 解决方案 > 巴马纳沙占卜Python程序

问题描述

我有一项任务需要编写一个 Python 程序来复制 Bamana 的风水实践。



这是我到目前为止写的代码:

dashes = str(input())

mod = dashes % 2

if mod > 0:
    print("0")
else:
    print("1")

它不起作用,所以有人可以帮助我吗?

谢谢你。

标签: python

解决方案


你错过了重要的一点:破折号的数量,使用str.count

line = input("Enter a list of dashes: ")
nb_dashes = line.count("-")
mod = nb_dashes % 2
if mod > 0:
    print("0")
else:
    print("1")

如您所知,您可以使用bool => int转换来打印 0 或 1

mod = nb_dashes % 2
print(int(mod == 0)) # True > 1, False > 0

推荐阅读