#🔒 Passing variables through parameters
55 messages · Page 1 of 1 (latest)
@pine ibex
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
why is my post deleted?
what
anyways
I needed some help regarding passing variables through parameters
!paste @pine ibex
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
By the name of your question, it sounds you come from a compiled language and wanted passing by reference? Is my guess correct?
Or is this about something else?
no
uh
def menuFeature(stdID):
print("Student Transcript Generation System")
print("==================================================")
print("1. Student Details")
print("2. Statistics")
print("3. Transcript based on major courses")
print("4. Transcript based on minor courses")
print("5. Full Transcript")
print("6. Previous Request")
print("7. Select another student")
print("8. Terminate System")
print("==================================================")
feature_number = int(input("Enter Your Feature: "))
print()
#The print statements will be changed later on
if feature_number == 1:
detailsFeature(stdID)
elif feature_number == 2:
statisticsFeature(stdID)
elif feature_number == 3:
majorTranscriptFeature(stdID)
elif feature_number == 4:
minorTranscriptFeature(stdID)
elif feature_number == 5:
fullTranscriptFeature()
elif feature_number == 6:
previousRequestsFeature(stdID)
elif feature_number == 7:
newStudentFeature()
elif feature_number == 8:
terminateFeature()
else:
print("Invalid feature")
before this code, there's a long ass code of just asking for an ID which is stored in stdID as seen being transferred through parameters so yeah I have these 8 functions and in the last function, which is terminateFeature, it needs to display the total number of times the other 7 functions have been used which will be stored in the requests variable, before exiting, I badly need help in building that🥲
here are the last two codes that needs modification:
def newStudentFeature():
confirm = input("New student entry? Y/N: ").strip().upper()
if confirm == "Y":
print('\n' * 100)
main()
else:
terminateFeature()
def terminateFeature():
print(f"There were {requests} requests made.")
exit()
the thing is I wanna create a variable named requests but i cant use global or class
that variable counts how many times functions 1-7 is called
btw function 1 to 7 reverts back to the menuFeature which is the first code here
so sorry again for comitting so many mistakes😭im just so stressed out rn..
Meaning they execute it?
Please don't, you're making it recursive.
The functions should just end, the menu should be in a loop instead (to run until user selects to terminate)
i actually want to send the file cuz i want someone to review my code🙏
the thing is yeah i wanted to do it this way but my teacher wants it that way and if we dont follow, we're gonna have a failing mark even tho it's a better code
what I meant is after every function, it reverts back to the menu and yeah
💀 what
If you do a loop and there's no functions running other functions, you can just keep the counter inside the menu function and increase it every time...
With the teacher's thing, you gotta use a global variable
yeah fuck, we cant use a global variable
btw
uh
mmm
lemme try that suggestion
the loop one
how can I do that + the counter thing
thank you so much🙏you're a very good person T^T i cant figure it out myself since im in my first year with no knowledge in python, im just trying to do it myself with self study cuz our teacher doesnt wanna teach us
Menu would be basically in a while True
Since the terminate does exit(), you don't even need a break, lol (but you'd normally break in the else and run terminate outside the loop).
Then the counter will be just added any time user selects 1-7
And passed as argument to terminate
yea i get that wait lemme uh try that
but how about the counter one?
how can i put it? like
yk
OH WAIT
WAIT WAIT WAIT
I THINK I GOT IT
WAIT A SEC
lemme try to do it
You can increase the counter in each if/elif
Or just add if 0<feature_number<8: and increase the counter
oki thank uuu will do
But it's weird the new student exits the whole program on N answer.
Just don't add the entry but still keep running the program.
As I said, keeping track of the counter inside the menu is only possible if the 1-7 functions don't run each other (includes running 8 terminate, because you gotta pass the counter to it)
oh oki oki mmmmm
Btw did you learn classes?
Because if those things were inside a class, you could use that to keep the counter without using the global keyword
yea about that...
self study shit
cuz our teacher is shit
doesnt teach us
uh
i did this
def menuFeature(stdID):
while True:
requests = 0
print("Student Transcript Generation System")
print("==================================================")
print("1. Student Details")
print("2. Statistics")
print("3. Transcript based on major courses")
print("4. Transcript based on minor courses")
print("5. Full Transcript")
print("6. Previous Request")
print("7. Select another student")
print("8. Terminate System")
print("==================================================")
feature_number = int(input("Enter Your Feature: "))
print()
#The print statements will be changed later on
if feature_number == 1:
detailsFeature(stdID)
elif feature_number == 2:
statisticsFeature(stdID)
elif feature_number == 3:
majorTranscriptFeature(stdID)
elif feature_number == 4:
minorTranscriptFeature(stdID)
elif feature_number == 5:
fullTranscriptFeature()
elif feature_number == 6:
previousRequestsFeature(stdID)
elif feature_number == 7:
newStudentFeature(requests)
elif feature_number == 8:
terminateFeature(requests)
else:
print("Invalid feature")
requests += 1
the counter doesnt increase whyyyy T^T
i'll try to fix it
ah just wrong placement of starting value
you set it to 0 each loop
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.