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.
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:
count += 1
And this was the output:
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.
With the placeholder, it would look like:
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.
2,4,3,1,6 One line without a 5 here.
2,2,4,3,3 One line without a 5 here.
6,1,6,3,1 One line without a 5 here.
1,6,2,2,3 One line without a 5 here.
4,2,1,3,2 One line without a 5 here.