I tried to do something like this, but as I said, I’m very new to Python (basically a complete noob). Anyway, I tried my code with the following sample data using “4” as the user_num value, but I didn’t get the exact results that I wanted. This would be the Data.csv file.
1,2,3,4,5
2,4,6,8,10
1,5,7,8,12
1,4,7,9,10
6,8,14,32,5
7,14,68,43,19
2,4,6,8,12
1,8,9,16,32
This is my code:
from _csv import reader
user_num = input("Enter a number: ")
count = 0
with open("Data.csv", "r") as file:
csv = reader(file)
for row in csv:
if user_num in row:
print("-")
else:
count += 1
print(count)
And this was the output:
-
-
1
-
2
3
-
4
In the end, I’d like it to look like the following. The “-” is just a placeholder for now so I can see what it’s doing.
1
2
1
With the placeholder, it would look like:
-
-
1
-
2
-
1
I hope this all makes sense. Thanks for the help! Also, this isn’t for school or anything. It’s just a thing I want to make for myself. Its purpose is to average the lines in the end. For example, lets say each row were the results of a die being tossed 5 times and I want to calculate the average amount of times a die can be tossed without getting a 5 in a set. The program would count how many rounds in a row didn’t have a 5 each time and assign that a numerical value. After that, I would take all of the numerical values and average them. For this example, the average is 1.6, so you can just say that you’re likely to go two times in a row without rolling a 5 since the values would be 1,2,2.
1,1,3,5,5
2,4,3,1,6 One line without a 5 here.
2,5,6,3,1
1,4,3,6,5
2,2,4,3,3 One line without a 5 here.
6,1,6,3,1 One line without a 5 here.
4,4,3,5,1
1,6,2,2,3 One line without a 5 here.
4,2,1,3,2 One line without a 5 here.
3,5,1,2,6