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

  • Home
  • SEARCH
  • 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 8578921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:30:10+00:00 2026-06-11T20:30:10+00:00

I think my largest problem is I don’t know how to ask the question

  • 0

I think my largest problem is I don’t know how to ask the question of what it is exactly that I am looking for.

I stole most the code from a flashcard program from http://www.tuxradar.com/content/code-project-build-flash-card-app and modified it a bit to suit my own needs. However, when I get the answer correct it still says I’ve gotten it wrong.
Here is my code:

#!/usr/bin/env python
import os
import random
import time

file1 = open('/root/first.txt', 'w')
file2 = open('/root/second.txt', 'w')

file1.writelines('1\n2\n3\n4\n5')
file2.writelines('0,2\n1,3\n2,4\n3,5\n4,6')

time.sleep(1)

file1.close
file2.close

time.sleep(1)

file1 = open('/root/first.txt', 'r')
file2 = open('/root/second.txt', 'r')

count = 0
score = 0
tries = int(raw_input('How many tries?'))
start_time = time.time()

f1content = file1.readlines()
f2content = file2.readlines()

try:
    while count < tries:
        os.system('clear')

        wordnum = random.randint(0, len(f1content)-1)
        correct = str(f2content[wordnum])

        print 'Number:', f1content[wordnum], ''

        answer = input('\nSurrounding numbers?')

        if answer == correct:
            raw_input('\nCorrect! Hit enter...')
            score = score + 1
        else:
            print '\nNope, It\'s', correct
            raw_input('Hit enter to try a new one...')

        count = count + 1

except SyntaxError:
    print 'you must enter a value, starting over'
    os.system('./flash.py')

finally:
    file1.close
    file2.close
    os.system('rm /root/first.txt')
    os.system('rm /root/second.txt')

stop_time = time.time() - start_time
print '\nIt took you', stop_time / 60, 'minutes to get', score, 'out of', count, 'correct'

I postulate that my problem lies in Line 35 where I define correct as

correct = str(f2content[wordnum])

The reason I think this is because if it gives me 1 and I know that the correct answer is 0,2 and I type that in, it say’s nope, it’s 0,2. This suggests that in plain text it is the exact same to the human eye but that the computer is reading it as something different. I tried to make it a string because of this and making it an integer causes an error. I’m really stuck and am sure it’s something so simple but I am just not seeing it. Any help would be appreciated. Even if it is just a point in the right direction of where I can find the answer.

  • 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-11T20:30:11+00:00Added an answer on June 11, 2026 at 8:30 pm

    First, I fixed all the problems given in the comments above.

    Instead of writeline, use write:

    file1.write('1\n2\n3\n4\n5')
    file2.write('0,2\n1,3\n2,4\n3,5\n4,6')
    

    Add the parentheses to close:

    file1.close()
    file2.close()
    

    Indent everything between the while and the end of the try.

    Debug by adding the following before the comparison:

    print repr(answer), repr(correct)
    

    Also, I went through and changed all the /root/first.txt, etc. into just first.txt, so it’ll work on a system that doesn’t have a writable directory named /root (which most systems won’t).

    So, when I run it, I see this:

    Number: 4
    
    
    Surrounding numbers?3,5
    (3, 5) '3,5\n'
    
    Nope, It's 3,5
    
    Hit enter to try a new one...
    

    So clearly, answer is the tuple (3, 5) rather than the string 3,5, and correct is the string 3,5\n rather than the string 3,5.

    If you read the documentation for input, it should be clear why answer is wrong. It’s trying to interpret my 3,5 as a Python expression, and it’s a perfectly valid way to write the tuple (3, 5), so that’s why I get. To fix that, you want to use raw_input.

    If you read the documentation for readlines, it should be clear why each line has a newline at the end. There are a number of ways around this.

    Having fixed that, it still fails at the end, because it never creates the files table.txt and pocket.txt that it tries to delete. Whatever you were trying to do there, you appear to have missed something. I just commented out those lines.

    While you’re at it, I’d change the open/readlines/close into a more modern Python pattern, using with and treating the file as just a string iterator. And hardcoding paths like /root/first.txt isn’t a very good idea.

    Anyway, I don’t want to give the exact changes needed, because this feels like homework, but I think the above is enough information for you to fix it yourself, and hopefully learn a little about how to debug the next problem on your own. If you still have problems, ask away.

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

Sidebar

Related Questions

I've got a pretty simple question, I think.. I've got a database field that
I don't know if this is the place to ask about algorithms. But let's
I've got quite typical problem, I think. I know there were similar topics here
Think my problem is I am trying to sum a count in the same
I think that handlers in android are tools to get different objects that are
I think I've figured out the problem. I'm using a IP webcam stream, doing
I think I have a basic understanding of this, but am hoping that someone
I think everyone knows this site http://pinterest.com/ and I don't want to create site
I think this could be a very easy question for you. But I have
This is a very general question but it's based on a specific problem. I've

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.