Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:07:08+00:00 2026-06-11T06:07:08+00:00

The problem I am having involves reading in from a file, and using python’s

  • 0

The problem I am having involves reading in from a file, and using python’s turtle to draw shapes based on what is read in.

The text file looks like this (but no spaces in between the lines):

r 0.0 200.0 50.0 100.0 blue

c 0.0 200.0 40.0 red

p 0.0 200.0 3 40.0 black

the problem is going from a line in the file to something like
r = Rectangle(0.0,200.0,50.0,100.0,”blue”)

if the line starts with a “r”, use my Rectangle method, if its starts with a “c” use my Circle method (or “p” use Polygon())

I have all the shape methods down I just don’t know how to get it from the file to say draw a rectangle(or circle/polygon) at these coordinates with these side lengths and this color. This is what I have so far, but it seems too complicated and is getting messy. Any help or ideas are appreciated, thanks.

shapeCollection=[]
with open(name,"r") as f:
    for line in f:
        for i in line.split():
            shapeCollection.append(i)
print(shapeCollection)
for each in shapeCollection:
    if each == "r":
        #(xCor) = each+1
    elif each == "c":
        #
    elif each == "p":
        #
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:07:10+00:00Added an answer on June 11, 2026 at 6:07 am

    Do something like this

    for line in f:
     inp = line.split()
     x = float(inp[1])
     y = float(inp[2])
    
     if(inp[0] == 'r'):
      DrawRectangle(x,y,float(inp[3]),float(inp[4]),inp[5])
    

    This just basically shows how to parse the input. It is pretty simple and you see how it could easily be applied to the other 2 cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problem using mvc:resources in spring 3.1 configuration. Initially i was working
Is there a way to read a file's data but continue reading the data
I'm having a very weird problem.I'm working on an assignment that involves building a
I have this problem having to display my jasper report on my grails application.
Im having problem in my UIscrollView ,this is what I have done: Whenever a
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I am having problem with previewing custom performance counters with PerflibV2. Performance Monitor shows
I am having problem to get a numerical value for this expression where I
I'm having problem with datagrid view. I have attached an image with the code
I am having problem with drawing multiple lines during repaint. The code is as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.