Python Forum
Quick Help - Timers - Need Small Solution for Working Code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick Help - Timers - Need Small Solution for Working Code
#4
(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!!!
Reply


Messages In This Thread
RE: Quick Help - Timers - Need Small Solution for Working Code - by EwH006 - Nov-16-2020, 06:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 1,111 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 1,103 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,144 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,205 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  small code for sampel asn1ate borys 0 932 Jul-26-2022, 10:48 AM
Last Post: borys
  Can someone explain this small snippet of code like I am a 5 year old? PythonNPC 3 1,364 Apr-08-2022, 05:54 PM
Last Post: deanhystad
  My Code isn't working... End3r 4 2,101 Mar-21-2022, 10:12 AM
Last Post: End3r
  please looking for typo in my code (solution please) jamie_01 1 1,361 Jan-12-2022, 06:45 AM
Last Post: Gribouillis
  i need help with a small code Jacobthefirst 1 1,576 Sep-22-2021, 03:33 PM
Last Post: bowlofred
  Newbie - code solution explained Stjude1982 2 1,992 Sep-16-2021, 08:54 AM
Last Post: Stjude1982

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020