Question

I'm making a quiz in python and was wondering how I would read different text files...

I'm making a quiz in python and was wondering how I would read different text files depending on the user

For example, the user can pick 'easy', 'medium' or 'hard' and the quiz would loads one of 3 text files depending on what button they clicked.

Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

file_dict= {'easy':'quiz_easy.txt','medium':'quiz_medium.txt','hard':'quiz_hard.txt'}

def button_click(qtype):
print("Trying to open file...",file_dict[qtype])
if qtype in file_dict.keys():
try:
f = open(file_dict[qtype], "r")
print("The file", file_dict[qtype], "has opened.")
except:
print("Error opening file", file_dict[qtype])
else:
print("file is not defined for the button", qtype)
  
button_click('easy')
button_click('medium')
button_click('hard')

Add a comment
Know the answer?
Add Answer to:
I'm making a quiz in python and was wondering how I would read different text files...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In c++. I have 6 different text files that I want my program to read during...

    In c++. I have 6 different text files that I want my program to read during different runs. How would I make it so that i can read a select whichi file I want it to read during each run?

  • I am writing an angular application, and I'm wondering how much client side memory to use....

    I am writing an angular application, and I'm wondering how much client side memory to use. I'm currently working on a scenario where there are 2 dropdowns. The second will load new values depending on the selection of the first. I'm thinking the max # of total records in the 2nd dropdown would be around 2000-3000 items, each being around 2k each. Each selection would display probably 10-15 items of the 2000-3000. Should I load the entire array into memory...

  • ****THIS IS A 2 PART QUESTION! I ONLY NEED THE ANSWER TO PART 2 ON HOW...

    ****THIS IS A 2 PART QUESTION! I ONLY NEED THE ANSWER TO PART 2 ON HOW TO SEND THE DATA SERIALIZED**** Write a c# program that stores student grades in a text file and read grades from a text file.  The program has the following GUI: There are four buttons: Create File, Save Case, Close File and Load File.  Initially, only the Create File and Load File buttons are enabled.  If the user clicks the Create File button, a Save File Dialog window...

  • Im stuck. can someone please show me code on how i can make text appear on...

    Im stuck. can someone please show me code on how i can make text appear on html canvas. i want to create a form where someone for example put their name and when submit button is clicked on the form it appear on the canvas. i am using html javascript. please show code for javascript, canvas, and html. please let me know if im not making sense. Thank you

  • can anyone show me how this code would look in python, I'm studying python while taking...

    can anyone show me how this code would look in python, I'm studying python while taking some classes. I can't seem to understand what this is asking for. • Phase 1 Requirements Code submitted for Phase 1 will only have the following capability. Any additional coding will result in the loss of point. • code will have the main function, including looping until the user enters input of 12 • code will call the printMenu() function • The printMenu() function...

  • Hi I would like to revise the codes below to bring all text files I have...

    Hi I would like to revise the codes below to bring all text files I have text file 0 from 10 I will give you link here https://drive.google.com/open?id=1LnWqv8ftzARx5Rhf7HtVlVkLVlcA1FtI when tokenizer read all tokens from the 10 files which attached above, I would like to arrange it in alphabetical order and want to make same word tokens being merged. For instance, You are my son? You are my son and good friend! you are the only one whom I loved. The...

  • How do i write a program to read muliple files? i can read one but i...

    How do i write a program to read muliple files? i can read one but i need to read 10: 0.txt - 9.txt Here is the code for reading one but i need to read 10 text files and print the frequencies of all the letters a - z, upper and lowercase, in one take. here is the output i should get #include <stdio.h> #include <stdlib.h> #include <string.h> #include <omp.h> int main() { double start_time = omp_get_wtime(); char str[1000); int...

  • This needs to be written in Python. I'm writing this but I'd love to see how...

    This needs to be written in Python. I'm writing this but I'd love to see how others would do it. I have idea to make a program to keep track of reading. Set goal per day. Input minutes per day & book read. Could accumulate for whole month. Input daily, but you can input it all at the end of the week if you want. I want the user to be prompted to enter a numerical value and book for...

  • I'm reading through Mark Seeman's Dependency Injection in .NET (excellent read so far) and something is...

    I'm reading through Mark Seeman's Dependency Injection in .NET (excellent read so far) and something is escaping me. If the application's architecture is like [DAL] => [BLL] <= [UI], with the Business Logic Layer free of dependencies upon Data Access and UI layers (and both dependent upon the BLL), and if the composition root is located in the UI layer, then how on Earth are we supposed to be able to bind the interface of a type in the BLL...

  • I really need some help with some direction as to how this should look. I'm wondering...

    I really need some help with some direction as to how this should look. I'm wondering how I should start. Cumulative Spreadsheet Analysis Beginning with Chapter 2, each chapter in this text will include a spreadsheet assignment based on the financial information of a fictitious company named Skywalker Enterprises. The assignments start out simple—in this chapter you are not asked to do much more than set up financial statement formats and input some numbers. In succeeding chapters, the spreadsheets will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT