Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What's wrong with my code? I ' m struggling to find out where I am going wrong and would love advice. Changed it about 8

What's wrong with my code?
I'm struggling to find out where I am going wrong and would love advice. Changed it about 8 times and can't figure it out.
My code:
def find_largest():
print("Please enter 10 numbers and this program will display the largest.")
largest = None
for i in range(1,11):
while True:
try:
num = int(input(f"Please enter number {i}: "))
if num>0:
break
else:
print("Please enter a positive integer.")
except ValueError:
print("Please enter a valid integer.")
if largest is None or num > largest:
largest=num
print(f"The largest number was {largest}")
# Call the function to execute
find_largest()
Pycharm Output
Pycharm Outcome:
Please enter 10 numbers and this program will display the largest.
Please enter number 1: 51
Please enter number 2: 20
Please enter number 3: 57
Please enter number 4: 89
Please enter number 5: 79
Please enter number 6: 100
Please enter number 7: 80
Please enter number 8: 87
Please enter number 9: 9
Please enter number 10: 1
The largest number was 100
Process finished with exit code 0
EOFError:
Traceback (most recent call last):
File "/autograder/source/Lab5A.py", line 38, in
find_largest()
File "/autograder/source/Lab5A.py", line 23, in find_largest
num = int(input(f"Please enter number{i}: "))
EOFError: EOF when reading a line
Traceback (most recent call last):
File "/autograder/source/Lab5A.py", line 38, in
find_largest()
File "/autograder/source/Lab5A.py", line 23, in find_largest
num = int(input(f"Please enter number{i}: "))
EOFError: EOF when reading a line
Traceback (most recent call last):
File "/autograder/source/Lab5A.py", line 38, in
find_largest()
File "/autograder/source/Lab5A.py", line 23, in find_largest
num = int(input(f"Please enter number{i}: "))
EOFError: EOF when reading a line
python3: can't open file '/autograder/source/Lab5B.py': [Errno 2] No such file or directory
python3: can't open file '/autograder/source/Lab5B.py': [Errno 2] No such file or directory
python3: can't open file '/autograder/source/Lab5B.py': [Errno 2] No such file or directory
python3: can't open file '/autograder/source/Lab5B.py': [Errno 2] No such file or directory
python3: can't open file '/autograder/source/Lab5C.py': [Errno 2] No such file or directory
python3: can't open file '/autograder/source/Lab5C.py': [Errno 2] No such file or directory
python3: can't open file '/autograder/source/Lab5C.py': [Errno 2] No such file or directory
python3: can't open file '/autograder/source/Lab5C.py': [Errno 2] No such file or directory
Websites IDE:
Expected:
Please enter 10 numbers and this program will display the largest.
Please enter number 1:
Please enter number 2:
Please enter number 3:
Please enter number 4:
Please enter number 5:
Please enter number 6:
Please enter number 7:
Please enter number 8:
Please enter number 9:
Please enter number 10:
The largest number was 34
Your Output:
Please enter 10 numbers and this program will display the largest.
Please enter number1: Please enter number2: Please enter number3: Please enter number4: Please enter number5: Please enter number6: Please enter number7: Please enter number8: Please enter number9: Please enter a positive integer.
Please enter number9: Please enter a positive integer.
Please enter number9:
I've rewritten the code multiple times based on the power point slides my school gives. Ran it through both Pychart and Replit which it ran correctly.
What I am expecting is the code to run the same on pychart, replit and Gradescope.
original assignment (python)
Lab5A: Largest of 10
For this lab, please use a for loop. The goal of this exercise is for you to create a program that will ask the user to input 10 positive integer numbers, one at a time. While it does this the program should also keep track of the largest number it has seen so far. After it has run 10 times, it should display the largest number you input.
The user input is indicated in bold.
Sample output:
Please enter 10 numbers and this program will display the largest.
Please enter number 1: 50
Please enter number 2: 51
Please enter number 3: 10
Please enter number 4: 1
Please enter number 5: 99
Please enter number 6: 1000
Please enter number 7: 1010
Please enter number 8: 42
Please enter number 9: 89
Please enter number 10: 1000
The largest number was 1010

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions