How can i create a exam generator program in python 3?

Viewed 124

*I'm a newbie to python, I'm currently trying to create some random programs. I came accross this challenge. Would love to see how it can be solved, unfortunately I couldn't make this program. I understand that we should use the random module and also the file handling functions in python. If any detail is unclear I can re explain it

Write a program, which will help the user to generate exam tickets. there are 2 files given . 1) with the exercises(exercises.txt): it contains 30 exercises, each are already written on a new line. 2) we are given the students.txt file. Each line has a full name of a student. The program should allow the user to input the number of exercises which should be generated for the student. The new created ticket should have the students name with .txt file extension. The number must not exceed 30 exercises, if it does we should give them a new try to input the correct number. The exercises should be shuffled(randomized) .

 import random
def logic():
   number_input = int(input('sheiyvanet cifri'))
   students_file = open('students.txt', 'r', encoding='utf8')
   exercises_file = open('exercises.txt', 'r', encoding='utf8')
   new_ticket_file = open('newTicket.txt', 'w')
   while True:
        if(number_input < 30):
            new_ticket_file.write(str(random.shuffle(exercises_file.readlines())))
            new_ticket_file.close()
            break
        else :
            continue

logic()

1 Answers
  1. Please do not simply provide a question and ask for it to be solved. Instead, show your current work and specify what is wrong with it.

  2. Show examples of the text files, as in a few lines from each so that all viewers can properly understand it.

A good starting step is to write a piece of code that does only one thing. Eg:

Input a number.
The number must not exceed 30 exercises, if it does we should give them a new try to input the correct number.

Then write one that achieves a different part of your question. Try connecting these pieces. If it blows up or you really can't work it out, post a new question with the stuff you made and ask for help.

Related