S
S
Sergey Zolotarev2020-10-07 19:42:19
Python
Sergey Zolotarev, 2020-10-07 19:42:19

How to correctly determine lottery tickets in accordance with the conditions of the problem?

Good evening!
It remains for me to almost finish solving the problem in Python using algorithms, the conditions of which you will see in the screenshots at this link.
The code is written almost correctly, the initial data was processed by the program in accordance with the conditions for solving the problem. And there is a small error in the results:
Instead of displaying the correct result:

Unlucky
Lucky
Lucky

The program produced the following result:
Lucky
Lucky
Unlucky

Implementing an almost correct logical action for determining odd numbers, I must do what is required from the task itself, but it turned a little ;-(

Are there any correct variants of the algorithm for determining lottery tickets?
A code with a note will be available in the comments to this question so that you can understand what I'm talking about ;-)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2020-10-08
@seregazolotaryow64

And I'm not satisfied with the "only" problematic piece of code:
if ndata[i] % 2 != 0 and nf % 2 != 0: lucky += 1
There is some kind of nonsense written there. What's with the parity check?
You need to count how many numbers from trda are in ndata and print Lucky if you counted at least 3 (reread the problem statement).
Accordingly, it should be something like

if nf == ndata[s]: cnt+=1
...
if cnt >=3:  print('Lucky')
    else: print('Unlucky')

You also have nested loops on the same variable i, maybe in python it is possible, but this is usually a very bad idea.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question