lundi 30 août 2021

How do I print two random string using the random module?

import random
user = "Jude"

file = ["do not lie", "do not cheat", "do not be bitter in anger", "do love all, is the greatest commandment"]
task = (input(f"There are four task in the task menu \nHow many task do wish to complete today {user}: "))
options1, options2, options3, options4 = file
for task in [random.randrange(*sorted([options1, options2, options3, options4])) for i in range(3)]:
    while True:
        if task == "1":
            print(options1)
            break
        elif task == "2":
            print(options1)
            print(options2)
            break
        elif task == "3":
            print(options1)
            print(options2)
            print(options3)
            break
        elif task == "4":
            print(options1)
            print(options2)
            print(options3)
            print(options4)
            break
        else:
            print("No task to be done today")
            break

The program I am trying to write is expected to print the number of task the user input. Example, if the user input 2 task, the program is expected to randomly select two task for the user and print it out. I am unable to make the program work properly, it keeps giving this error;

"C:\Users\Jude E\PycharmProjects\pythonProject3\venv\Scripts\python.exe" D:/python_tutorial/todolist.py
There are four task in the task menu  How many task do wish to complete today Jude: 2 Traceback (most recent call last):   File "D:\python_tutorial\todolist.py", line 7, in <module>
    for task in [random.randrange(*sorted([options1, options2, options3, options4])) for i in range(3)]:   File "D:\python_tutorial\todolist.py", line 7, in <listcomp>
    for task in [random.randrange(*sorted([options1, options2, options3, options4])) for i in range(3)]: TypeError: randrange() takes from 2 to 4 positional arguments but 5 were given

Please how do I fix it, or how do I get this program working?

Thanks.




Aucun commentaire:

Enregistrer un commentaire