Write the python code for this programn that a year 9 student could understand The…
- User
Write the python code for this programn that a year 9 student could understand The program should: The teacher should be able to enter their password and username If right then they can start to enter values If it is wrong make them enter again The teacher should be able to enter three values respective to their topic and the student’s name. Once they have entered all of the values they will get a question asking them if they have entered all the student’s scores. If they say ‘yes’ then give them the class average by adding up all the score and dividing by number of students If they say ‘no’ then repeat the paragraph before
- Assistant
Here's a Python code that implements the given requirements:
# Teacher login credentials correct_username = "teacher" correct_password = "password" # Check teacher's login credentials username = input("Enter your username: ") password = input("Enter your password: ") while username != correct_username or password != correct_password: print("Incorrect username or password. Please try again.") username = input("Enter your username: ") password = input("Enter your password: ") print("Logged in successfully!") # Get number of students num_students = int(input("Enter the number of students: ")) # Initialize variables student_scores = {} total_scores = 0 # Get scores for each student for i in range(num_students): student_name = input("Enter student's name: ") score = float(input(f"Enter score for {student_name}: ")) student_scores[student_name] = score total_scores += score # Get class average while True: all_scores_entered = input("Have you entered all the student's scores? (yes/no): ") if all_scores_entered.lower() == "yes": class_average = total_scores / num_students print("Class average:", class_average) break elif all_scores_entered.lower() == "no": for i in range(num_students): student_name = input("Enter student's name: ") score = float(input(f"Enter score for {student_name}: ")) student_scores[student_name] = score total_scores += score else: print("Invalid input. Please try again.")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.