SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 314 Weeks Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 20 Dec 2017 My Price 10.00

Python program to read in a file (Qsand0pts.txt) of quiz questions

In Python:

Create a Python program to read in a file (Qsand0pts.txt) of quiz questions and answers into a list. Each question set is stored inside the file using 3 lines.

·        The first line contains the questions itself.

·        The second line contains the choices for the question. The choices are separated by two characters, a dot and underscore; each question may have a different number of choices. The choices should be displayed with the number associated with them, starting with number one.

·        The third line contains the number of the correct choice.

Each question set should be stored as a tuple in the list. Display all of the question sets to the screen in the following format:

1. Question

1)     First option

2)     Second option

3)     Third option

 

2. Question

1)     First option

2)     Second option

3)     Third option

...

Read in a file of names (names.txt). As you read each name, choose 5 unique and random questions from the questions file. Store the questions in a set. Enter the name into a dictionary where the name is the key and the set of questions is the value. Print the names and questions neatly to the screen where the questions are in ascending order.

 

Create a Python program to read in the ‘Qsand0pts.txt’ file into a list and to read in the ‘togive.txt’ file into a dictionary as given in the “Lab Preparation” Section. Allow the user to select a name and then give the associated quiz using the questions in the question set stored in the dictionary. Show the user his/her score at the end of the quiz. Allow the user to select as many names as desired and give the quiz for each name.

  • import random

    #random.randint(n,m) generates n <= random integer <= m

    #random.random() generates 0 <= random float < 1.0

    #random.randrange(n,m,s) generates n <= random integer < m with step value s

    #random.uniform(n,m) generates n <= random float <= m

    #random.choice(sequence) selects a random element from the sequence and returns it

    #random.shuffle(sequence) shuffles the order of the sequence in place

    #random.sample(sequence,num) generates a new sequence by sampling k elements from the original sequence

     

    #demo randint

    #print 5 random numbers seeded with 5

    print('seed 5 randint():',end=' ')

    random.seed(5)

    for i in range(0,5):

        print (random.randint(1,10),end=' ')

    print()

    #print 5 random numbers seeded with the current time

    print('seed current time randint():',end=' ')

    random.seed()

    for i in range(0,5):

        print (random.randint(1,10),end=' ')

    print()

    #print another 5 random numbers seeded with the current time

    print('seed current time randint():',end=' ')

    random.seed()

    for i in range(0,5):

        print (random.randint(1,10),end=' ')

    print()

    #print 5 random numbers seeded with 5 to show the same sequence occurs

    print('seed 5: randint()',end=' ')

    random.seed(5)

    for i in range(0,5):

        print (random.randint(1,10),end=' ')

    print()

     

    #demo random

    #print 5 random numbers

    random.seed(5)

    print('seed 5 random():',end=' ')

    for i in range(0,5):

        print (random.random(),end=' ')

    print()

     

    #demo randrange

    print('randrange(0,10,2) =',random.randrange(0,10,2))

    #demo uniform

    print('uniform(2.0,10.0) =',random.uniform(2.0,10.0))

    #demo choice

    print('choice(\'abcdefg\') =',random.choice('abcdefg'))

    #demo shuffle

    a = [1,2,3,4,5]

    random.shuffle(a)

    print('shuffle([1,2,3,4,5]) =',a)

    #demo sample

    print('sample([1,2,3,4,5],3) =',random.sample([1,2,3,4,5],3))

     

    #seeding the random number generator each time a random number is generated

    for i in range(0,5):

        random.seed(5)

        print(random.randint(1,10),end=' ')

    print()

     

Attachments:

Answers

(5)
Status NEW Posted 20 Dec 2017 12:12 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)