0

Hi I have question in Python, If my question is duplicate. Please link to the solution that have the similarity between mine

I have this function which set idinput from input() however, the value don't change and from another function it read it as 0, and AddStudents() Function doesn't change it value. It append to the list correctly but in another function it read it as initial 0

materials = {}
student = {}
sidlist = []
idinput = 0

 
# Add Students
def AddStudent():
 idinput = int(input("ID: "))
 name = input("Name: ")
 lastname = input("LName:")
 student.update({idinput: {name: lastname}})
 # Append ID To ID List
 sidlist.append(int(idinput))
 AddMaterial()


def AddMaterial():
 materialinp = input("MAT:")
 degreeinp = int(input("DEGREE:"))
 sidlist.append(idinput)
 materials.update({idinput: {materialinp: degreeinp}})

 askUserToContinue = input("Do you like to add more materials?: y/n")
 if askUserToContinue.lower() == "y":
  AddMaterial()
 else:
  print("Do you like to add more student or do search y/n")
  askUserChoice = input(": ")
  if askUserChoice.lower() == "y":
   AddStudent()
  else:
   GetInfo()

and Thank you.

  • Question solved, Sorry I was out of my mind – Mohammed Alamer Dec 29 '20 at 04:04
  • You want to add `global idinput, name, lastname` in any functions that _assign_ those global variables. BTW, 4 space indents make it easier for the rest of us to quickly scan your code. Its a good style to use. – tdelaney Dec 29 '20 at 04:04
  • you should learn how to use arguments in functions and `return` - instead of `global` – furas Dec 29 '20 at 05:05

0 Answers0