Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我需要写一本字典,里面有字符串和值_Python - Fatal编程技术网

Python 我需要写一本字典,里面有字符串和值

Python 我需要写一本字典,里面有字符串和值,python,Python,我需要制作一个接受值和字符串的字典,并提示用户添加、修改和删除信息。当我尝试运行时,有一个错误显示“中断”外部循环,请有人帮助我 您的代码没有正确缩进。Python中的缩进(前导空格)用于对语句进行分组。此注释后的代码#选项1将保存学生姓名和成绩不在while循环中,最后的中断也不在while循环中。因此出现了错误消息 这会奏效的。choice=input(“输入您的选择:”)之后的所有代码在循环之外。您需要将其向右移动4个空格。 #start the student array Student

我需要制作一个接受值和字符串的字典,并提示用户添加、修改和删除信息。当我尝试运行时,有一个错误显示“中断”外部循环,请有人帮助我

您的代码没有正确缩进。Python中的缩进(前导空格)用于对语句进行分组。此注释后的代码
#选项1将保存学生姓名和成绩
不在while循环中,最后的
中断
也不在while循环中。因此出现了错误消息


这会奏效的。
choice=input(“输入您的选择:”)之后的所有代码在循环之外。您需要将其向右移动4个空格。
#start the student array
Student = {}
#Menu to prompt the user if he wants to add, remove or modify a grade
while (True):
    print ("1. Add Student")
    print ("2. Remove Student")
    print ("3. Modify Grade")
    print ("4. Print all grades")
    print ("5. Exit")

    print("Welcome to the school dashboard system, choose one of the options");
    #prompt the user for a choice
    choice = input("Enter your choice: ");
#choice 1 will save the student name and grade
if (choice == 1):
#raw input meaning is accepting both values and strings
    name = raw_input("Enter student name: ")
   grade = raw_input("Enter the grade for the student: ")
   Student[name] = grade

#choice number 2 will delete the student from the list
elif (choice == 2):
    name = raw_input("Enter the student name: ");
#delete the student from the list
    del Student[name]

#choice number 3 will modify the grade for the student
elif (choice == 3):
    name = raw_input("Enter the student name: ")
    grade = raw_input("Enter the new grade for the student: ")
 #save in the student array
    Student[name] = grade

#choice number 4 will print all of the information about students and grades
elif (choice == 4):
#print the student list
    print (Student)

#This choice will exit the menu
elif (choice == 5):
     print("Thanks for using the System")
     break