Nov-16-2020, 06:14 PM
(Jan-19-2019, 11:47 PM)SheeppOSU Wrote: Here you go. This should do the trick
import random import time def random_line(pname): lines = open(pname).read().splitlines() return random.choice(lines) def start(): #if you dont want to have to type start for it to work just delete this and backspace everything back one for x in range(1,10): #change the 10 to how many times you want it to print print('') print(random_line('listofplays.txt')) print('') Go = input('Hit Enter to See the Next Play')
Sorry I didn't get back, thank you all for your input, I added +1 for you SheeppOSU as well as snippsat. I've since expanded on this code a tad. I currently have a IF-STATEMENT that isn't functioning properly. I will post the modified code and output below.
The issue with my script is very small. It lies within my IF STATEMENT. If you take a look at the code you will see what the IF STATEMENT is setup to do, however it does not do this. It will print the second option, or the ELSE portion every time. Outside the if-statement, all the code works as long as you have a list associated with the script to point to.
import random import time def random_line(pname): lines = open(pname).read().splitlines() return random.choice(lines) def real_world_fn(): for x in range(1,10): #change the 10 to how many times you want it to print print('') print(random_line('listofplays.txt')) print('') Go = input('Hit Enter to See the Next Play') def nba2k_fn(): for x in range(1,10): #change the 10 to how many times you want it to print print('') print(random_line('listofplays.txt')) print('') Go = input('Hit Enter to See the Next Play') print('Welcome to the eSports Play Call App') print('') print('') print('1. Real World Scenario') print('2. NBA2K') print('') print('') #print('The eSports Play Call App functions on two levels, please choose from the following') Menu = input('The eSports Play Call App functions on two levels, please choose operational level: ') if Menu == 1: print('HELLO REAL WORLD') else: print('HELLO NBA2K')
Output:Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
= RESTART: C:\Users\HOUSTONE\Desktop\ITN290-6C1 - IT Capstone Project\drafts\v1\new 4.py
Welcome to the eSports Play Call App
1. Real World Scenario
2. NBA2K
The eSports Play Call App functions on two levels, please choose operational level: 1
HELLO NBA2K
>>>
= RESTART: C:\Users\HOUSTONE\Desktop\ITN290-6C1 - IT Capstone Project\drafts\v1\new 4.py
Welcome to the eSports Play Call App
1. Real World Scenario
2. NBA2K
The eSports Play Call App functions on two levels, please choose operational level: 2
HELLO NBA2K
>>>
Let me know what yall think the issue is, THANKS!!!