Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
broken if statement????
#1
ok so this sample code is intended to run (at this time) infinetly until i re-run the code (f5)

my current problem is after i call the button function. i am attempting the first part of what will be an if elsif else statement to choose Longsound, Shortsound, or Medsound based on input. (the input will eventually be one of three buttons in a glove instead of 1, 2, or 3 on a keyboard, and eventually the random number will be transferred to the sound functions to pick one of 13 sound files(i was thinking something similar to a switch statement in C++) in each function.)
for now the if statement just to test to see if i can print long sound to the screen is not working
this will eventually be run on a raspberry pi.............. :(

it runs otherwise with no errors.
import random
press = 0
def button():    
    press=input("enter\n")
    print('pressed ', press)
    return press
   
def RNG():#defnine random number generator
    x=0
    rnv = random.randint(1,13)
    print('Rnv is ',rnv)
    return rnv

def Longsound(): #plays a long sound
    RNG()#calls random number generator
    print("longsound")
    print(RNG())
    x=RNG()
    print("l",x,".wav")

def Shortsound():#plays short sound
    RNG()
    print("shortsound")

def Medsound():
    RNG()
    print("mediumsound")


    
def main():
    print("\n\nhello world\n")
    press = button()
    print("main post button",press)
    if press == 1:#attempting to call (print the name) a function
        print("longsound")
'''
main program run
'''
while True:   #loops program ill figure out how to exit and shutdown later
    main() #calls main program
    #if press == 1:#attempting to call (print the name) a function
        #print("longsound")
        
Reply
#2
input returns a string.  "1" is not equal to 1.  Either convert one to a string or the other to an int before the comparison.
Reply
#3
Wow duh Wall

Thanks. Why is it the simple things we over look
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is copying and pasting a block now broken? WagmoreBarkless 2 1,395 May-05-2022, 05:01 AM
Last Post: WagmoreBarkless
  Why is copying and pasting a block now broken? WagmoreBarkless 1 1,234 May-04-2022, 11:40 PM
Last Post: Larz60+
  BrokenPipeError: [Errno 32] Broken pipe throwaway34 6 9,324 May-06-2021, 05:39 AM
Last Post: throwaway34
  Python broken if moved to a different folder ecastrotns 3 2,455 Oct-26-2020, 10:53 PM
Last Post: ecastrotns
  STT: recognition connection failed: [Errno 32] Broken pipe GrahamBerends 0 5,073 Jul-18-2020, 11:00 PM
Last Post: GrahamBerends
  Python DateTime is broken 10OctNotOct10a1 8 4,748 Jan-03-2020, 07:54 AM
Last Post: snippsat
  Broken interpreter? fcktheworld587 1 2,268 Dec-26-2019, 08:29 PM
Last Post: snippsat
  String being broken up into single characters ammorgan 1 2,352 Dec-31-2018, 07:06 AM
Last Post: Gribouillis
  Speech (audio file, wav) to Text - Broken pipe Shobha 1 3,777 Nov-27-2018, 12:41 PM
Last Post: Larz60+
  SMTPLIB MIMEText HTML - Words being broken GaryK 2 3,778 Apr-16-2018, 04:08 PM
Last Post: GaryK

Forum Jump:

User Panel Messages

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