I have tried to run my python3 code in google code jam tests however it always gives me a runtime error when testing. I would like it to not give me a runtime error. I have tested on my ubuntu python3.5.3 and it works. I am not sure what causes the runtime error, Is there a way I could get the logs from google code jam or similar?
Here is the code.
if __name__ == "__main__":
testcases = input()
raw = []
while True:
inp = input()
if inp == "":
break
raw.append(inp)
print(raw)
Sorry if this is a newbie question. I am new to code jam and submitting my work online.
This should do the same as what you are trying to do as far as i know. try and lemme know.
If i know what you are trying to take as inputs, i would have been able to give a more specific answer :)
testcases = int(input())
for t in range(testcases):
raw = []
n = int(input())
for i in range(n):
inp = input()
raw.append(inp)
print(raw)
Related
i have this small program to assign issues to me, it works great on pycharm but when i compile it to exe with pyintaller it closes after the first run, ignoring the time.sleep and running again creating a loop to check for issues every 5 seconds.
why is that? how can i fix it?
import time
import winsound
from jira import JIRA
global lst_ignore
issue_var = ""
lst_ignore = []
def jira_login():
global user,token
user = 'user#cloud.com'
token = 'kj432hj43214YMzCyMLOe7682'
try:
options = {'server': 'https://cloud.atlassian.net'}
global jira
jira = JIRA(options=options, basic_auth=(user, token))
except Exception as e:
jira = ""
if '401' in str(e):
print("Login to JIRA failed. Check your username and password",e)
return jira
def check_issue():
jira_login()
size = 100000
start = 0 * 100000
search_query = 'status not in (Done, Closed,Canceled) and assignee is EMPTY and project = "Success" and reporter not in (57f778:f48131cb-b67d-43c7-b30d-2b58d98bd077)'
issues = jira.search_issues(search_query, start, size)
for issue in issues:
if issue not in lst_ignore:
winsound.Beep(2000, 1000)
issue.update(assignee={'accountId': '60f1d072a0de61930ad83770'})
print(issue, " : assinged to you!")
lst_ignore.append(issue)
def check():
check_issue()
time.sleep(5)
check()
if __name__ == '__main__':
check()
NEW ANSWER:___________________________________________________
(New info obtained from comment) If it says you don't have the module when running from the console, but it does from Pycharm, you probably have 2 different Interpreters. There are two steps you must take.
Using the terminal run: pip install jira
If it says it is already installed, uninstall using pip, and then reinstall.
Good Luck!
OLD ANSWER:____________________________________________________
It is hard to say. One thing I can tell you is that a recursive function is almost never a good idea.
So instead of:
def check():
check_issue()
time.sleep(5)
check()
if __name__ == '__main__':
check()
Try the following aproach:
RUNNING = True
def main():
while RUNNING:
check_issue()
time.sleep(5)
if __name__ == '__main__':
main()
After that you can implement that if some condition is met, it wil change the RUNNING constant to exit the program. Or, if it is a console-run program, then just use a keyboard-interrupt
I am trying to make this script get what im saying and print it out on terminal but im getting this error
TypeError: catching classes that do not inherit from BaseException is not allowed
for this I followed a tutorial and his worked just fine im running version 3.9.5 I have tried to look this up but nothing I found was helpful if you know please let me know
import speech_recognition
import pyttsx3
recognizer = speech_recognition.Recognizer()
while True:
try:
with speech_recognition.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic, duration=0.2)
audio = recognizer.listen(mic)
text = recognizer.recognize_google(audio)
text = text.lower()
print(f"Recognized {text}")
except speech_recognition.UnknownValueError():
recognizer = speech_recognition.Recognizer()
continue
Your
except speech_recognition.UnknownValueError():
should be
except speech_recognition.UnknownValueError:
i.e. it should name the type, not call it and use the return value.
I'm trying to build a speech recognition app in python,everything works fine but,when I'm executing program the first If condition always executes no matter what the input is.
import speech_recognition as sr
from gtts import gTTS
import os
from google_speech import Speech
import webbrowser
def speech():
while True:
try:
with sr.Microphone() as source:
r = sr.Recognizer()
audio = r.listen(source,timeout=3, phrase_time_limit=3)
x = r.recognize_google(audio)
print(x)
if 'hello' or 'Hello' or 'Hi' in x:
speech=Speech('Hello,How are you?','en')
speech.play()
print('Input: ',x)
print('output: Hello,How are you?',)
elif 'omkara' or 'Omkara' in x:
speech=Speech('Playing Omkara song on Youtube','en')
speech.play()
webbrowser.get('/usr/bin/google-chrome').open('https://youtu.be/NoPAKchuhxE?t=21')
except sr.UnknownValueError:
print("No clue what you said, listening again... \n")
speech()
if __name__ == '__main__':
print('Executine Voice based commands \n')
speech()
here is my code I have used while to continuously repeat the program but,In first if condition,it should only be executed when there is 'Hello','Hi' in input. First time I say 'Hi',if is valid then,but when the program loops again with another input like 'how are you' it still executes first IF condition,can anyone please help me with this.Thank you.
You use or in wrong way there. Try to use this code:
if any(check in x for check in ('hello', 'Hello', 'Hi')):
The problem occurs because if 'Hello' becomes True instantly. Once you have a condition which is true, it will always go to if condition.
You can try to check this using bool('Hello'). The solution is to check each string separately.
if ('hello' in x) or ('Hello' in x) or ('Hi' in x):
something
Im writing some code for my schools sign in/out system and im kind of confused with the output im getting
In essence im checking each line of students which looks like 'name theircode' for each student and checkign it aganist the input code which all works
but when im printing in logged times it rewrites the previous line.
how do i fix this?
Here is the code
import time
lunch = str('inout {0}.txt'.format(time.strftime("%Y-%m-%d")))
while True:
variable = input()
with open ('students.txt') as f:
for eachline in f:
name,rfid = eachline.rsplit(None,1)
if variable == rfid:
print("yay")
with open('inout.txt','w+') as fp:
log = str('{0} loggged at {1}(ID: {2})'.format(name,time.strftime("%H:%M"),rfid))
fp.write('\n')
fp.write(log)
else:
print("nope")
I am a beginner in Python programming. Using Python3 for class.
The code I have is:
#!/usr/binpython3
import arduino
def loop():
contin = True
while contin:
userinput = input()
if userinput == "quit":
contin = False
else:
contin = True
I am stuck at the "userinput = input()" portion of my code. For some reason, my program would not ask user for the input. How can I fix this?
Thank you!
Are you actually calling the function? That is, are you saying loop() at the end of your code?