Counting Positive and Negative NumbersA teacher wants to analyze the performance of students in a test. The test scores for the class of 20 students are given. Write a program that counts the number of positive and negative scores.Constraints:NAExample:Sample Input:102030-40-50-60-70-80-90-100110120130140150160170180190200Sample Output:Positive 13Negative 7Explanation:From the sample input--> Test score of 20 students Output-->13 Positive scores 7 Negative scores
Question
Counting Positive and Negative NumbersA teacher wants to analyze the performance of students in a test. The test scores for the class of 20 students are given. Write a program that counts the number of positive and negative scores.Constraints:NAExample:Sample Input:102030-40-50-60-70-80-90-100110120130140150160170180190200Sample Output:Positive 13Negative 7Explanation:From the sample input--> Test score of 20 students Output-->13 Positive scores 7 Negative scores
Solution
Here is a Python program that counts the number of positive and negative scores:
# Sample Input
scores = [10, 20, 30, -40, -50, -60, -70, -80, -90, -100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]
# Initialize counters for positive and negative scores
positive_count = 0
negative_count = 0
# Iterate over the scores
for score in scores:
# If the score is positive, increment the positive counter
if score > 0:
positive_count += 1
# If the score is negative, increment the negative counter
elif score < 0:
negative_count += 1
# Print the results
print("Positive:", positive_count)
print("Negative:", negative_count)
This program works by iterating over each score in the list. If the score is greater than 0, it increments the positive counter. If the score is less than 0, it increments the negative counter. At the end, it prints the number of positive and negative scores.
Similar Questions
Write a Java program that reads an unspecified number of scores anddetermines how many scores are above or equal to the average, and how many scoresare below the average. Enter a negative number to signify the end of the input. Assumethe maximum number of scores is 100.
write the follwing eanswer in psuedocode usuing the syntax of igcse computer sicence 0478 Three 1D arrays are used to record the score of a class of 25 students in 3 tests. Allow the teacher to enter the marks of each student, and reject any negative score. Find and display:The best score of each student out of all testsThe class average The highest average-scoring student Sample OutputT1 T2 T3 Best (Displayed) Avg(Used for class average / highest avg score)12 20 21 21 17.6623 20 22 23 21.66 12 11 15 15 12.66Class Average : 17.32Highest Average score is of roll no 2 with a score of 21.66
Problem StatementA computer science teacher assigned the students a programming task that calculates and displays grades based on test marks. The teacher wants the program to take a student's test mark as input and determine their grade using the following criteria:If the mark is between 90 and 100 (inclusive), assign grade A.If the mark is between 80 and 89 (inclusive), assign grade B.If the mark is between 70 and 79 (inclusive), assign grade C.If the mark is between 60 and 69 (inclusive), assign grade D.If the mark is between 45 and 59 (inclusive), assign grade E.For marks below 45 assign grade F.If the mark is greater than 100 or a negative number, it displays "Invalid input". Help the students to accomplish the given task.Note: This question helps in clearing AMCAT exam.Input format :The input consists of a single integer, representing the student's mark.Output format :The output displays "Grade: " followed by the grade for the given mark based on the given criteria.If the mark is greater than 100 or a negative number, the output displays "Invalid input".Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:0 ≤ student's mark ≤ 100Sample test cases :Input 1 :100Output 1 :Grade: AInput 2 :85Output 2 :Grade: BInput 3 :79Output 3 :Grade: CInput 4 :63Output 4 :Grade: DInput 5 :56Output 5 :Grade: EInput 6 :0Output 6 :Grade: FInput 7 :-5Output 7 :Invalid inputInput 8 :126Output 8 :Invalid input
A test has 50 questions. A student scores 1 mark for a correct answer, -1/3 for a wrong answer, and –1/6 for not attempting a question. If the net score of a student is 32, the number of questions answered wrongly by that student cannot be less than? radio_button_unchecked 6 radio_button_unchecked 12 radio_button_unchecked 3 radio_button_unchecked 4
Single File Programming QuestionProblem statementRaja is designing a simple game where players earn points based on their performance. Each player starts with a default score of 100. If a player completes a level, they earn 20 points. However, for each unsuccessful attempt, they lose 10 points. Additionally, if a player's score drops below 50, they are disqualified. Write a program that takes the number of successful and unsuccessful attempts from the user and calculates the player's final score using the Relational and Ternary operators.ExamplesInput215OutputThe player is disqualified.Explanation: In this case, the player has 2 successful attempts and 15 unsuccessful attempts.finalScore = 100 + (2 * 20) - (15 * 10) = 100 + 40 - 150 = -10Since the final score is below 50, the player is disqualified.Input5010OutputThe player's final score is 1000.Explanation: In this case, the player has 50 successful attempts and 10 unsuccessful attempts.finalScore = 100 + (50 * 20) - (10 * 10) = 100 + 1000 - 100 = 1000The final score is 1000, and it is greater than or equal to 50, so the player is not disqualified.Input format :The first line of input consists of an integer value 'n', representing the number of successful attempts.The second line of input consists of an integer value 'n1', representing the number of unsuccessful attempts.Output format :If the player is disqualified it displays as: "The player is disqualified."If the player is qualified, the final score is displayed in the format "The player's final score is [score]."Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ n ≤ 501 ≤ n1 ≤ 30Sample test cases :Input 1 :215Output 1 :The player is disqualified.Input 2 :1030Output 2 :The player is disqualified.Input 3 :5010Output 3 :The player's final score is 1000.Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.