1. (Count positive and negative numbers and compute the average of numbers) Writ
ID: 3777699 • Letter: 1
Question
1. (Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. Here is a simple run: Note; use python programming 2. (Find the two highest scores) Write a program that prompts the user to enter the number of students and each student’s score, and displays the highest and second highest scores. Note: use python programming 3. (Find numbers divisible by 5 or 6, but not both) Write a program that displays, ten numbers pre line, all the numbers from 100 to 200 that are divisible by 5 or , but not both. The numbers are separated by exactly one space. Note; use python programming
Explanation / Answer
Hi, it actually works in online compliers like ideone. That must be problem with your windows python environment. For other parts please post them separately.
Hey, it was working earlier in Python-2. Since python-3 changed raw_input API to input. It gave you error. I've fixed it according to Python-3 standards. Working code
pos = 0
neg = 0
avg = 0.0
a = input();
int_list = a.split(" ");
for b in int_list:
if int(b)>0:
pos = pos+1;
elif int(b)<0:
neg = neg+1;
else:
break;
avg = avg + int(b);
print (pos)
print (neg)
print (avg/(pos+neg))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.