Python Forum
Building first python program. Need a little guidance.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Building first python program. Need a little guidance.
#1
Hey. I'm Chris. I'm new to this forum and pretty new to python too. I've learned enough that I want to try building a small program that I can actually use.

I'm trying to make a simple little flashcard program that will run in the terminal. I have the questions and answers saved in .txt files. I've figured out how to get python to display the text in a file, but am having trouble displaying one thing in the file at a time.

The answers are on the same line as the questions, separated by a couple tabs.
How do I get python to display the first question then wait til I press enter to display the answer, then wait again for enter to display the next question, and so forth?
Reply
#2
(Oct-24-2018, 09:58 PM)Chrislw324 Wrote: I've figured out how to get python to display the text in a file, but am having trouble displaying one thing in the file at a time.
If you're doing file_object.read(), then you're doing it the hard way. The easy way to read files that's used 99% of the time, would already handle what you're trying to accomplish:
with open("my_file.txt") as my_file:
    for line in my_file:
        print(line)
Reply
#3
That prints the entire file.
Reply
#4
Yes, but it does so one thing at a time.

Please, show the code you've got now, what output you're getting, and what output you want to get.
Reply
#5
The code I currently have is your suggestion which displays the entire file.

Suppose I had a file with questions and answers separated by two tabs:

Question 1 <tab> <tab> Answer 1
Question 2 <tab> <tab> Answer 2
etc..

I'd like the output to just display Questions 1, then wait for me to press enter and then display Answer 1.
Then when I press enter again, Question 2 is displayed.
Reply
#6
This could give you a step in the right direction.
The csv module can also help, with the delimiter argument set to \t.
parts = line.split("\t")
print(parts)
Reply
#7
(Oct-24-2018, 09:58 PM)Chrislw324 Wrote: I've learned enough that I want to try building a small program that I can actually use.

(Oct-25-2018, 01:20 AM)Chrislw324 Wrote: The code I currently have is your suggestion which displays the entire file.

You claim you have learned enough, to try and build small program (with little guidance probably), yet everything you have is the code suggested by nilamo? If this is not a homework, you should try to work on what you already have and use what you have learned so far - e.g. working with files, string methods, console output/input, loop/iteration, etc..
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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Building a DoublyLinkedList in Python - - append method Drone4four 2 373 Jan-08-2024, 01:27 PM
Last Post: Drone4four
  building app in XCODE with python phantom115 2 833 Aug-02-2023, 11:56 AM
Last Post: phantom115
  Docker -building a python image saisankalpj 5 3,811 Jul-13-2022, 12:53 PM
Last Post: saisankalpj
  Building python (3.9.5) with different libexpat version (2.4.6) raghupcr 0 1,258 Feb-25-2022, 11:29 AM
Last Post: raghupcr
  Need some coding guidance for a task peny 5 2,135 Sep-27-2021, 02:02 PM
Last Post: peny
  Your Guidance caslor 1 2,100 Mar-28-2021, 09:34 PM
Last Post: Larz60+
  Solaris 10 building Python 3.8.3 problems. munocat 0 1,489 May-26-2020, 01:05 AM
Last Post: munocat
  Noob needing guidance.... bako 0 1,835 Mar-29-2020, 06:55 PM
Last Post: bako
  New Python learner looking for key word guidance naga 2 1,722 Nov-20-2019, 01:09 PM
Last Post: ChislaineWijdeven
  General Guidance in Project JMiller184 1 2,997 Oct-24-2017, 10:27 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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