Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Debugging
#1
Hey guys I keep getting this error:
Welcome to Course Average Tool.
Enter first number:
Traceback (most recent call last):
File "lab4d.py", line 37, in <module>
main()
File "lab4d.py", line 25, in main
grade_1 = int(input())
TypeError: input() missing 1 required positional argument: 'string'

This is my code:
def course_average(grade1, grade2, grade3):
   crse_avg = (grade1 + grade2 + grade3)/3
   return crse_avg
   
def main():
    print('Welcome to Course Average Tool.')
    print('Enter first number: ')
    grade_1 = int(input())
    print('Enter second number: ')
    grade_2 = int(input())
    print('Enter third number: ')
    grade_3 = int(input())
    
    course_average(grade_1, grade_2, grade_3)
    
    print('The average of',grade_1, ',', grade_2, 'and', grade_3, 'is', 
    course_average(grade_1,grade_2,grade_3))
  
# comment out this call to main() before you evauate with the checkmark icon  
main()
Reply
#2
Hello, the error happened because there was no value entered in the prompt. That means it gets an empty string, which is otherwise ok, but int() expects a value to cast from string to int.
Reply
#3
The code you post works fine, both in python3 and python2.
If you don't enter number as suggested by j.crater you will get error but different one (ValueError in python3 and SynatxError on python2).
Given that traceback refers to lines 37 and 25 (and you have just 20 lines) and that it expects positional argument called "string" I would guess you have extra code that override the built-in input() function (i.e. I guess you have defined your own input function)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
You are right buran, the error would be different. And good thinking with idea of overridden input() function!
I considered the empty string as cause of error due to OPs traceback:
Error:
Enter first number: Traceback (most recent call last):
-> nothing entered at the prompt
Reply


Forum Jump:

User Panel Messages

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