Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
108 views
in Technique[技术] by (71.8m points)

python - Developing expressions using and or not

Alice, Bob, Charlie, David, and Eve are friends trying to decide whether to go skiing or study next weekend. Each casts a vote. Let their votes be de- noted by predicates a, b, c, d, and e where each is True if the preference is for skiing, and False if the preference is for studying. Write a python formula (using and, or, not, and parentheses – no ”if” statements or other Python operators allowed) that is True if the majority wants to ski, and False if the majority wants to study. Note that you can break long lines in Python with a backslash. Hint: Do not make a function. The answer should be a single expression using variables a, b, c, d and e, plus operators and, or and not.

Example: (a or b or c) and (a or b or d)

question from:https://stackoverflow.com/questions/66061377/developing-expressions-using-and-or-not

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm going to assume this is a homework question and suggest you enumerate (in English, using the words and, or, not) all possible situations in which a majority want to ski, then translate that sentence into python code.

To start you out, consider the situation where Alice, Bob and Charlie want to ski - this is a majority - represented by the predicate (a and b and c)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...