Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with loops
#1
Hi everyone,

I have been trying to avoid doing this, but I'm taking a basic programming class online and I am at a total loss on how to do this assignment. Everything have tried just results in syntax errors. If someone can help point me in the right direction on how to even start this assignment, I would really appreciate it!

Assignment Instructions
Write a program that will provide important statistics for the grades in a class. The program will utilize a loop to read five floating-point grades from user input.
Ask the user to enter the values, then print the following data:
Average
Maximum
Minimum


Please help me figure out where I even begin with this problem.
Reply
#2
Show us what you've tried. Post the code (in Python tags, see Here are instructions for instructions), and post the full text of the syntax error you are getting.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Here is what I tried most recently (I've been trying a million different things all morning).

grades_list = float(input('Enter Grades:n')

total = 0
for iter in grades_list:
    total += iter
print("Max =", max)
print("Min =", min)
print("Avg =", total/len(grades_list))
The error I receive simply says: invalid syntax

The issue that I'm having is that the assignment does not go along with our lesson for this week. So I'm trying to teach myself about floating point numbers and how they work with loops.
Reply
#4
The code you posted has a syntax error because you missed a close-parenthesis on the first line.

Your assignment says to use a loop to read the values from the user, but you don't use a loop until after you've defined grades_list. Stick to trying to define grades_list fully before writing any additional code. Once you're confident you have that, then you should continue on, but it's a common beginner (bad) habit to write new code without verifying earlier code.
Reply
#5
Thank you! That helped me out, but now I'm getting this error message

[python]
Traceback (most recent call last):
File "C:/Users/reccles/Desktop/School/ITS320/ITS320_CTA4_Option1.py", line 22, in <module>
for iter in grades_list:
TypeError: 'float' object is not iterable
[\python]

Here is my overall issue: I don't understand how float numbers work with a loop. If I had a set of variables in front of me, I would know how to write a loop that would show the min, max, and average. I don't understand how to do this with the float variables and my textbook is absolutely no help. Can someone please help me to understand how these work together?
Reply
#6
You need to ask for the numbers within the loop. Just loop five times. Each time through loop get a new value, add it to the total, see if it's the lowest yet, and see if it's the highest yet.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#7
When you post an error, you should post the whole code that you used to reproduce the error. (You can omit lines after the error unless they're directly relevant to the question.)
Reply
#8
Oh, and use a forward slash (/) for the closing python tag.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

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