EOFError EOF when reading a line

0 votes

I wanted to define a function to make the perimeter of a rectangle. 
Code :

width = input()
height = input()
def rectanglePerimeter(width, height):
   return ((width + height)*2)
print(rectanglePerimeter(width, height))

I am getting an error in this code. What am I doing wrong here?

Apr 26, 2022 in Python by Kichu
• 19,050 points
4,320 views

1 answer to this question.

0 votes

The code:

width, height = map(int, input().split())
def rectanglePerimeter(width, height):
   return ((width + height)*2)
print(rectanglePerimeter(width, height))

Running it as this produces:

% echo "1 2" | test.py
6

The problem is that the  IDLE is simply passing a single string to your script. So such simple pipes only let you pass a single string, what you can do is to process this string, split it on whitespace, and convert the string fragments to ints yourself. 

You can also covert your input to ints like this:

width = int(input())
height = int(input())

I hope this helps.

answered Apr 28, 2022 by narikkadan
• 63,620 points

Related Questions In Python

+1 vote
1 answer

Reading a large file, line by line in Python

The correct, fully Pythonic way to read ...READ MORE

answered Aug 21, 2018 in Python by Priyaj
• 58,090 points
722 views
0 votes
1 answer

How to add a new line in Python?

You can use '\n' for a next ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
1,026 views
0 votes
2 answers

Obtaining a value when given a key in python dicionaries

Yes you can check below code dictionary = ...READ MORE

answered Nov 25, 2021 in Python by Suhas
603 views
0 votes
2 answers

In Python, how do I read a file line-by-line into a list?

readline function help to  read line in ...READ MORE

answered Jun 21, 2020 in Python by sahil
• 580 points
1,491 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,090 points
1,465 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,090 points
720 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,090 points
1,897 views
+1 vote
1 answer

How is raw_input() and input() in python3.x?

raw_input() was renamed to input() so now input() returns the exact string ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 58,090 points
710 views
0 votes
1 answer

Detect and exclude outliers in a pandas DataFrame

Function definition. This handles data when non-numeric attributes ...READ MORE

answered Apr 28, 2022 in Python by narikkadan
• 63,620 points
3,147 views
0 votes
1 answer

How to urlencode a querystring in Python?

Just pass your parameters into urlencode() like: >>> import urllib >>> ...READ MORE

answered Apr 28, 2022 in Python by narikkadan
• 63,620 points
431 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP