I am a newbie so please do not judge me, this is not the script its just an example of what it'd be like but I'd just like to get the understanding
n=input('Name: ') a=int(input('a: ')) b=int(input('b:' )) c=int(input('c: ' )) avg=(a+b+c)/3 print(avg) if avg>=19: print('distinction')basically I just want that input to be saved into a different file instead of just doing the output once when running the program(I know there are programs specifically made for this eg Excel I just thought it would make a great project :) Thanks
This was made on just notepad which is why I kinda messed up the print(avg) and also forgot the intends the actual code works fine C:
I don't understand this:
Quote: I just want that input to be saved into a different file instead of just doing the output once when running the program
Do you mean that you want to read input from a file and perform the calculation multiple times? Maybe having a file that looks like this:
Output:
3,6,9 12,15,18 21,24,27
And he output something like:
Output:
average(3,6,9) = 6.0 average(12,15,18) = 15.0 average(21,24,27) = 24.0, extinction
That could be done like this:
with open("test.txt", "r") as file: for line in file.readlines(): numbers = list(map(int, line.split(","))) average = sum(numbers) / len(numbers) suffix = ", extinction" if average >= 19 else "" print(f"average({line.strip()}) = {average}{suffix}")But there are better tools for this. Pandas can read csv files and do calculations.
import pandas as pd df = pd.read_csv("test.txt", names=["a", "b", "c"]) df["average"] = df.iloc[:, :].mean(axis=1) df["extinction"] = df.average >= 19 print(df)Output:
Output:
a b c average extinction 0 3 6 9 6.0 False 1 12 15 18 15.0 False 2 21 24 27 24.0 True
damn thanks that seems nice but really I got no idea what most of those do ;-; you seem to know your stuff so any tips? do you just memorize everything? Do you just get the hang of it doing projects and stuff over time? How long did it take u to get to this level :O sorry if I sound weird I'm just new and it lowkey makes me wanna quit whenever I see this confusing ah stuff. It's like Greek to me, well except I'm Greek

df.iloc[:, :] is a pandas command. To understand what it does, read the pandas iloc documentation. Pandas documentation is very good.
To find out if iloc is the right tool to use for a problem, use google. There are a lot of pandas users, so any question you have has been asked and answered. When I wrote my example I googled "pandas row average". I don't use pandas enough to remember everything about it, and for what I do, loc and iloc are not something I often use.