Python Forum
Problem with a homework
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with a homework
#1
Hello,

I am trying to create a program which reads a number N>=2 and creates a list. Then it fills the list with numbers and finds the average of them. Finally, it finds the amount of numbers which are greater than the average and it shows the percentage of them. There is a problem in my code, but I can't understand what it is. The problem is that it doesn't run at all. I believe it is probably a syntax error or something, but I don't know what. I use Python 3.6.4 at Windows 10 if that helps. I am a beginner at coding and python, so please be gentle.

Thank you in advance

Here is my code:

A=[]
average=0
max=0

N=int(input("Give the number of data of the list\n\n")
if (N<2):
    print ("The number you gave is wrong\n\n")
    while (N<2):
        N=int(input("Give the number of data of the list again\n\n")

print ("Give the numbers of the list\n\n")
for i in range(1,N):
    A[i]=int input
    average=average+A[i]

average=average/N
print ("The average is", average)

for i in range (1,N):
    if (A[i]>average):
        max++

num=100/N
max=max*num
print("The percentage of the data which are grater than the average is %s%", max
Reply
#2
your syntax error is the result of line 9 and 1 missing a closing parenthesis.

Also this is very non-pythonic code. Let alone not even runnable because some of it is not even valid python code. To be honest it looks like you never read a python tutorial ....like you just wrote C code with some python keywords and its indentation.

++ is not an operator in python and for good reason. You dont need to increment like you do in C/c++ so much. You loop over sequences element by element.

There is no type declarations in python so im not sure what this is suppose to be?
Quote:A[i]=int input

Use the format method for inserting variables into a string

Single char names are bad variables in any language. And capped names are meant for class names.
Recommended Tutorials:
Reply
#3
Thank you very much for your help. I searched a little more and I solved everything. Now it works perfectly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with a formula 1 kind of homework claroque 2 1,412 Jun-20-2023, 09:58 PM
Last Post: claroque
  Bakery Problem.. Can you Help My Homework Cemvrs 1 2,361 Jan-14-2022, 05:47 PM
Last Post: Yoriz
  Need help with a homework problem on logical operators voodoo 3 4,595 Jun-28-2019, 03:45 PM
Last Post: jefsummers
  Homework Problem csascott 1 2,277 Oct-27-2018, 04:44 AM
Last Post: scidam
  Homework Problem Travisbulls34 1 2,950 Sep-11-2018, 04:04 PM
Last Post: ichabod801
  Help with homework problem - iterating a function midnitetots12 4 3,502 Feb-21-2018, 10:51 PM
Last Post: nilamo
  Homework problem Dem_Prorammer 1 3,798 May-20-2017, 07:49 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020